DSCResources/cBinPlace/cBinPlace.psm1
function Get-TargetResource { [CmdletBinding()] [OutputType([Hashtable])] param([Parameter(Mandatory=$true)] [string] $OutputPath) @{ OutputPath = $outputPath Base64Content = try { [Convert]::ToBase64String([IO.File]::ReadAllBytes($outputPath)) } catch { $null } } } function Set-TargetResource { [CmdletBinding()] param([Parameter(Mandatory=$true)] [string] $OutputPath, [Parameter()] [string] $Base64Content) if (-not (Test-Path $outputPath)) { $nf = New-Item -Path $outputPath -Force -ItemType File } [IO.File]::WriteAllBytes($outputPath, [Convert]::FromBase64String($base64Content)) } function Test-TargetResource { [CmdletBinding()] [OutputType([bool])] param([Parameter(Mandatory=$true)] [string] $OutputPath, [Parameter()] [string] $Base64Content) if (-not [IO.File]::Exists($OutputPath)) { return $false } $b64 = [Convert]::FromBase64String($Base64Content) $md5 = [Security.Cryptography.MD5]::Create() $hash1 = [BitConverter]::ToString($md5.ComputeHash($b64)) $hash2 = [BitConverter]::ToString($md5.ComputeHash([IO.File]::ReadAllBytes($OutputPath))) $hash1 -eq $hash2 } Export-ModuleMember -Function Get-TargetResource, Set-TargetResource, Test-TargetResource |