Skip to content

Instantly share code, notes, and snippets.

@divgo
Created January 21, 2018 17:29
Show Gist options
  • Save divgo/ba92cac56b65a65f7209e43a21dc4afd to your computer and use it in GitHub Desktop.
Save divgo/ba92cac56b65a65f7209e43a21dc4afd to your computer and use it in GitHub Desktop.
# The DSC configuration that will generate metaconfigurations
[DscLocalConfigurationManager()]
Configuration DscMetaConfigs
{
param
(
[Parameter(Mandatory=$True)]
[String]$RegistrationUrl,
[Parameter(Mandatory=$True)]
[String]$RegistrationKey,
[String[]]$ComputerName = "localhost",
[Int]$RefreshFrequencyMins = 30,
[Int]$ConfigurationModeFrequencyMins = 15,
[String]$ConfigurationMode = "ApplyAndAutoCorrect",
[String]$NodeConfigurationName,
[Boolean]$RebootNodeIfNeeded= $True,
[String]$ActionAfterReboot = "ContinueConfiguration",
[Boolean]$AllowModuleOverwrite = $False,
[Boolean]$ReportOnly
)
if(!$NodeConfigurationName -or $NodeConfigurationName -eq "")
{
$ConfigurationNames = $null
}
else
{
$ConfigurationNames = @($NodeConfigurationName)
}
if($ReportOnly)
{
$RefreshMode = "PUSH"
}
else
{
$RefreshMode = "PULL"
}
Node $ComputerName
{
Settings
{
RefreshFrequencyMins = $RefreshFrequencyMins
RefreshMode = $RefreshMode
ConfigurationMode = $ConfigurationMode
AllowModuleOverwrite = $AllowModuleOverwrite
RebootNodeIfNeeded = $RebootNodeIfNeeded
ActionAfterReboot = $ActionAfterReboot
ConfigurationModeFrequencyMins = $ConfigurationModeFrequencyMins
}
if(!$ReportOnly)
{
ConfigurationRepositoryWeb AzureAutomationDSC
{
ServerUrl = $RegistrationUrl
RegistrationKey = $RegistrationKey
ConfigurationNames = $ConfigurationNames
}
ResourceRepositoryWeb AzureAutomationDSC
{
ServerUrl = $RegistrationUrl
RegistrationKey = $RegistrationKey
}
}
ReportServerWeb AzureAutomationDSC
{
ServerUrl = $RegistrationUrl
RegistrationKey = $RegistrationKey
}
}
}
# Create the metaconfigurations
# TODO: edit the below as needed for your use case
$Params = @{
RegistrationUrl = $args[1]
RegistrationKey = $args[0]
NodeConfigurationName = $args[2];
ConfigurationMode = $args[3];
}
# Use PowerShell splatting to pass parameters to the DSC configuration being invoked
# For more info about splatting, run: Get-Help -Name about_Splatting
DscMetaConfigs @Params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment