Last active
August 8, 2019 13:14
-
-
Save matt-FFFFFF/b5231fa3f09b7e58fcf0e288e01d7156 to your computer and use it in GitHub Desktop.
PowerShell DSC Configure LocalConfigurationManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param | |
( | |
[Parameter(Mandatory=$True)] | |
[ValidateSet("pull","push")] | |
[String]$mode, | |
[Parameter] | |
$RegistrationUrl, | |
[Parameter] | |
[PSCredential]$RegistrationKey, | |
[Int]$RefreshFrequencyMins = 30, | |
[Int]$ConfigurationModeFrequencyMins = 15, | |
[String]$ConfigurationMode = "ApplyAndMonitor", | |
[String]$NodeConfigurationName, | |
[Switch]$RebootNodeIfNeeded = $False, | |
[String]$ActionAfterReboot = "ContinueConfiguration", | |
[Switch]$AllowModuleOverwrite = $False, | |
[String]$Timestamp = "" | |
) | |
[DscLocalConfigurationManager()] | |
Configuration LCMConfigPull | |
{ | |
if(!$RefreshFrequencyMins -or $RefreshFrequencyMins -eq "") | |
{ | |
$RefreshFrequencyMins = 30 | |
} | |
if(!$ConfigurationModeFrequencyMins -or $ConfigurationModeFrequencyMins -eq "") | |
{ | |
$ConfigurationModeFrequencyMins = 15 | |
} | |
if(!$ConfigurationMode -or $ConfigurationMode -eq "") | |
{ | |
$ConfigurationMode = "ApplyAndMonitor" | |
} | |
if(!$ActionAfterReboot -or $ActionAfterReboot -eq "") | |
{ | |
$ActionAfterReboot = "ContinueConfiguration" | |
} | |
if(!$NodeConfigurationName -or $NodeConfigurationName -eq "") | |
{ | |
$ConfigurationNames = $null | |
} | |
else | |
{ | |
$ConfigurationNames = @($NodeConfigurationName) | |
} | |
Settings | |
{ | |
RefreshFrequencyMins = $RefreshFrequencyMins | |
RefreshMode = 'PULL' | |
ConfigurationMode = $ConfigurationMode | |
AllowModuleOverwrite = $AllowModuleOverwrite | |
RebootNodeIfNeeded = $RebootNodeIfNeeded | |
ActionAfterReboot = $ActionAfterReboot | |
ConfigurationModeFrequencyMins = $ConfigurationModeFrequencyMins | |
} | |
ConfigurationRepositoryWeb AzureAutomationDSC | |
{ | |
ServerUrl = $RegistrationUrl | |
RegistrationKey = $RegistrationKey.GetNetworkCredential().Password | |
ConfigurationNames = $ConfigurationNames | |
} | |
ResourceRepositoryWeb AzureAutomationDSC | |
{ | |
ServerUrl = $RegistrationUrl | |
RegistrationKey = $RegistrationKey.GetNetworkCredential().Password | |
} | |
ReportServerWeb AzureAutomationDSC | |
{ | |
ServerUrl = $RegistrationUrl | |
RegistrationKey = $RegistrationKey.GetNetworkCredential().Password | |
} | |
} | |
[DscLocalConfigurationManager()] | |
Configuration LCMConfigPush | |
{ | |
if(!$RefreshFrequencyMins -or $RefreshFrequencyMins -eq "") | |
{ | |
$RefreshFrequencyMins = 30 | |
} | |
if(!$ConfigurationModeFrequencyMins -or $ConfigurationModeFrequencyMins -eq "") | |
{ | |
$ConfigurationModeFrequencyMins = 15 | |
} | |
if(!$ConfigurationMode -or $ConfigurationMode -eq "") | |
{ | |
$ConfigurationMode = "ApplyAndMonitor" | |
} | |
if(!$ActionAfterReboot -or $ActionAfterReboot -eq "") | |
{ | |
$ActionAfterReboot = "ContinueConfiguration" | |
} | |
Settings | |
{ | |
RefreshFrequencyMins = $RefreshFrequencyMins | |
RefreshMode = 'Push' | |
ConfigurationMode = $ConfigurationMode | |
AllowModuleOverwrite = $AllowModuleOverwrite | |
RebootNodeIfNeeded = $RebootNodeIfNeeded | |
ActionAfterReboot = $ActionAfterReboot | |
ConfigurationModeFrequencyMins = $ConfigurationModeFrequencyMins | |
} | |
} | |
switch ($mode) { | |
'pull' { | |
LCMConfigPull; | |
Set-DscLocalConfigurationManager -Path '.\LCMConfigPull' -Verbose -Force; | |
break | |
} | |
'push' { | |
LCMConfigPush; | |
Set-DscLocalConfigurationManager -Path '.\LCMConfigPush' -Verbose -Force; | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment