Advertisement
Moktart

Parameter Magic

Oct 27th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Function LoadParameters {
  3.     if ($PSScriptRoot) {$ScriptPath = $PSScriptRoot} else {$ScriptPath = "C:\EIC\Deploy"}
  4.     [xml]$Script:XML = Get-Content "$ScriptPath\Settings.xml"
  5.     $SpecialNodes = @("Hosts","DNSRecords","DerivedParameters")
  6.     $ExclusionXPath = ""
  7.     $SpecialNodes | % { $ExclusionXpath += "[not(self::$_)]" }
  8.     $ConfigNodes = $XML | Select-XML -XPath "//Configuration/*$ExclusionXpath"
  9.  
  10.     $ConfigNodes | % { $_.Node.ChildNodes.Name | % { Set-Variable $_ -Value ($xml.SelectSingleNode("//$_").innertext) -Scope Script } }
  11.     $XML.Configuration.Hosts.ChildNodes | % { Set-Variable $_.Name -Value $_ -Scope Script }
  12.    
  13.     $DerivedParameters = $xml | Select-XML -XPath "//Configuration/DerivedParameters"
  14.     $DerivedParameters | % { $_.Node.ChildNodes.Name | %{ Set-Variable $_ -Value (& ([scriptblock]::create("$($xml.SelectSingleNode(""//$_"").innertext)"))) -Scope Script -Force }}
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement