Skip to content

Instantly share code, notes, and snippets.

@JamesDawson
JamesDawson / SimpleConfig.ps1
Last active December 19, 2015 11:09
A simple PowerShell Desired State Configuration script (accompanies this blog post: )
configuration SimpleConfig
{
node LAB-WEB01
{
File MarkerFile
{
DestinationPath = 'C:\deployed.txt'
Contents = ""
Requires = "[Group]FooGroup","[Registry]EnableRdp"
}
configuration SimpleConfig2
{
node LAB-WEB01
{
File MarkerFile
{
DestinationPath = 'C:\deployed.txt'
Contents = ""
Requires = "[Group]FooGroup","[Registry]EnableRdp"
}
Script SetTimezone
{
GetScript = { return @{ Timezone = ("{0}" -f (tzutil.exe /g)) } }
TestScript = { return (tzutil.exe /g) -ieq "GMT Standard Time" }
SetScript = { tzutil.exe /s "GMT Standard Time" }
}
configuration DscSecurity
{
node LAB-WEB01
{
ScriptEx UserInfo
{
GetScript = { return $null }
TestScript = {
Write-Verbose ("ENV username: '{0}'" -f $env:USERNAME)
Write-Verbose ("Windows Identity: '{0}'" -f [System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
configuration DscSecurity
{
node LAB-WEB01
{
Script UserInfo
{
GetScript = { return $null }
TestScript = {
Write-Verbose ("ENV username: '{0}'" -f $env:USERNAME)
Write-Verbose ("Windows Identity: '{0}'" -f [System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
$cred = Get-Credential
configuration DscSecurity
{
node LAB-WEB01
{
Script UserInfo
{
GetScript = { return $null }
TestScript = {
Configuration PullDemo
{
Node Server01
{
Computer RenameServer01
{
Name = "NewHostName"
}
}
}
Configuration SetPullMode
{
Node Server01
{
# Set the DSC engine (LCM) to Pull mode
DesiredStateConfigurationSettings LCM
{
ConfigurationID = "e528dee8-6f0b-4885-98a1-1ee4d8e86d82"
ConfigurationMode = "Pull"
DownloadManagerName = "WebDownloadManager"
Configuration SetPullMode
{
Node Server01
{
# Set the DSC engine (LCM) to Pull mode
LocalConfigurationManager
{
ConfigurationID = "e528dee8-6f0b-4885-98a1-1ee4d8e86d82"
ConfigurationMode = "ApplyOnly"
RefreshMode = "Pull"
param
(
$resources = @(),
$pullServerRoot = "C:\ProgramData\PSDSCPullServer"
)
function New-Hash
{
param
(