Created
February 7, 2018 01:42
-
-
Save gaelcolas/24ae3a7a405ab820dfc0e593d8241baa to your computer and use it in GitHub Desktop.
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
function Global:Get-DscSplattedResource { | |
[CmdletBinding()] | |
Param( | |
[String] | |
$ResourceName, | |
[String] | |
$ExecutionName, | |
[hashtable] | |
$Properties, | |
[switch] | |
$NoInvoke | |
) | |
# Remove Case Sensitivity of ordered Dictionary or Hashtables | |
$Properties = @{}+$Properties | |
$stringBuilder = [System.Text.StringBuilder]::new() | |
$null = $stringBuilder.AppendLine("Param([hashtable]`$Parameters)") | |
$null = $stringBuilder.AppendLine() | |
$null = $stringBuilder.AppendLine(" $ResourceName '$ExecutionName' { ") | |
foreach($PropertyName in $Properties.keys) { | |
$null = $stringBuilder.AppendLine("$PropertyName = `$(`$Parameters['$PropertyName'])") | |
} | |
$null = $stringBuilder.AppendLine("}") | |
Write-Debug ("Generated Resource Block = {0}" -f $stringBuilder.ToString()) | |
if($NoInvoke) { | |
[scriptblock]::Create($stringBuilder.ToString()) | |
} | |
else { | |
[scriptblock]::Create($stringBuilder.ToString()).Invoke($Properties) | |
} | |
} | |
Set-Alias -Name x -Value Get-DscSplattedResource -scope Global |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment