Skip to content

Instantly share code, notes, and snippets.

@dlwyatt
Last active September 26, 2016 18:35
Show Gist options
  • Save dlwyatt/a8e4720238e279d1fdf2 to your computer and use it in GitHub Desktop.
Save dlwyatt/a8e4720238e279d1fdf2 to your computer and use it in GitHub Desktop.
Resolve ConfigurationData updates
if (-not $PSBoundParameters.ContainsKey('ConfigurationData')) {
Write-Verbose ""
Write-Verbose "Resolving ConfigurationData"
$ScopeToCheck = 1
do {
try {
$ConfigurationData = Get-Variable -scope $ScopeToCheck -Name 'ConfigurationData' -ValueOnly -ErrorAction Stop
}
catch {
Write-Verbose "`t`tNothing in scope $ScopeToCheck for ConfigurationData"
}
$ScopeToCheck++
} until ($ScopeToCheck -gt 5 -or ($ConfigurationData -is [hashtable] -and $ConfigurationData.Keys.Count -gt 0))
if ($ConfigurationData -isnot [hashtable] -or $ConfigurationData.Keys.Count -eq 0) {
throw 'Failed to resolve ConfigurationData. Please confirm that $ConfigurationData is property set in a scope above this Resolve-DscConfigurationProperty or passed to Resolve-DscConfigurationProperty via the ConfigurationData parameter.'
}
else {
$PSBoundParameters.Add('ConfigurationData', $ConfigurationData)
}
}
if ($null -eq $ConfigurationData)
{
Write-Verbose ""
Write-Verbose "Resolving ConfigurationData"
$ConfigurationData = $PSCmdlet.GetVariableValue('ConfigurationData')
if ($ConfigurationData -isnot [hashtable])
{
throw 'Failed to resolve ConfigurationData. Please confirm that $ConfigurationData is property set in a scope above this Resolve-DscConfigurationProperty or passed to Resolve-DscConfigurationProperty via the ConfigurationData parameter.'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment