adding script resource

This commit is contained in:
Mariah Breakey
2016-12-15 19:08:38 -08:00
parent b9aa4e9e58
commit ca45108e98
11 changed files with 1116 additions and 1 deletions
+62
View File
@@ -0,0 +1,62 @@
<#
.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
}
}
}
}
}