Files
PowerShell-PSDscResources/Examples/Sample_Script.ps1
T
Simon Heather 2a7b5eef2b Revert "Fix example dir BOM files"
This reverts commit 590a77441f.
2019-04-28 18:49:16 +01:00

63 lines
1.6 KiB
PowerShell

<#
.SYNOPSIS
Creates a file at the given file path with the specified content through the Script resource.
.PARAMETER FilePath
The path at which to create the file.
.PARAMETER FileContent
The content to set for the new file.
#>
Configuration ScriptExample {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$FilePath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$FileContent
)
Import-DscResource -ModuleName 'PSDscResources'
Node localhost
{
Script ScriptExample
{
SetScript = {
$streamWriter = New-Object -TypeName 'System.IO.StreamWriter' -ArgumentList @( $using:FilePath )
$streamWriter.WriteLine($using:FileContent)
$streamWriter.Close()
}
TestScript = {
if (Test-Path -Path $using:FilePath)
{
$fileContent = Get-Content -Path $using:filePath -Raw
return $fileContent -eq $using:FileContent
}
else
{
return $false
}
}
GetScript = {
$fileContent = $null
if (Test-Path -Path $using:FilePath)
{
$fileContent = Get-Content -Path $using:filePath -Raw
}
return @{
Result = Get-Content -Path $fileContent
}
}
}
}
}