Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $env = "Test"
- $myDictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
- $xmlfile = [xml] (Get-Content "file-name")
- $xmlfile.SelectNodes("descendant::configuration/environment[@id='$($env)']/descendant::text()[normalize-space()]") | ? Value | % { $myDictionary.Add($_.ParentNode.ToString(), $_.Value) }
- Key Value
- ---- -----
- smtpserver smtp1.org
- type test
- encryption <add key ="DB1" value="mhu0VrvzBBlYjPbxh+EQk0zdY"/>
- <add key ="DB2" value="DVvHAq2EVKF5fmYYiUUJ/g=="/>
- <add key="DB3" value="dkcdowefnwlwkli/" />
- //configuration/environment[@id='target_id_here']/*
- PS C:Usershar07> $xml = [xml]@"
- >> <configuration>
- >> <environment id="Test">
- >> <smtpserver>smtp1.org</smtpserver>
- >> <type>test</type>
- >> <encryptioninfo>
- >> <add key ="DB1" value="mhu0VrvzBBlYjPbxh+EQk0zdY"/>
- >> <add key ="DB2" value="DVvHAq2EVKF5fmYYiUUJ/g=="/>
- >> <add key="DB3" value="dkcdowefnwlwkli/" />
- >> </encryptioninfo>
- >> </environment>
- >> </configuration>
- >> "@
- PS C:Usershar07> $env = "Test"
- PS C:Usershar07> $myDictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
- PS C:Usershar07> $xml.SelectNodes("//configuration/environment[@id='$($env)']/*") | % { $myDictionary.Add($_.ToString(), $_.InnerXml) }
- PS C:Usershar07> $myDictionary
- Key Value
- --- -----
- smtpserver smtp1.org
- type test
- encryptioninfo <add key="DB1" value="mhu0VrvzBBlYjPbxh+EQk0zdY" /><add key="DB2" value="DVvHAq2EVKF5fmYYiUUJ/g==" />...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement