Advertisement
Guest User

Untitled

a guest
May 4th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. $env = "Test"
  2. $myDictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
  3. $xmlfile = [xml] (Get-Content "file-name")
  4. $xmlfile.SelectNodes("descendant::configuration/environment[@id='$($env)']/descendant::text()[normalize-space()]") | ? Value | % { $myDictionary.Add($_.ParentNode.ToString(), $_.Value) }
  5.  
  6. Key Value
  7. ---- -----
  8. smtpserver smtp1.org
  9. type test
  10. encryption <add key ="DB1" value="mhu0VrvzBBlYjPbxh+EQk0zdY"/>
  11. <add key ="DB2" value="DVvHAq2EVKF5fmYYiUUJ/g=="/>
  12. <add key="DB3" value="dkcdowefnwlwkli/" />
  13.  
  14. //configuration/environment[@id='target_id_here']/*
  15.  
  16. PS C:Usershar07> $xml = [xml]@"
  17. >> <configuration>
  18. >> <environment id="Test">
  19. >> <smtpserver>smtp1.org</smtpserver>
  20. >> <type>test</type>
  21. >> <encryptioninfo>
  22. >> <add key ="DB1" value="mhu0VrvzBBlYjPbxh+EQk0zdY"/>
  23. >> <add key ="DB2" value="DVvHAq2EVKF5fmYYiUUJ/g=="/>
  24. >> <add key="DB3" value="dkcdowefnwlwkli/" />
  25. >> </encryptioninfo>
  26. >> </environment>
  27. >> </configuration>
  28. >> "@
  29. PS C:Usershar07> $env = "Test"
  30. PS C:Usershar07> $myDictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
  31. PS C:Usershar07> $xml.SelectNodes("//configuration/environment[@id='$($env)']/*") | % { $myDictionary.Add($_.ToString(), $_.InnerXml) }
  32. PS C:Usershar07> $myDictionary
  33.  
  34. Key Value
  35. --- -----
  36. smtpserver smtp1.org
  37. type test
  38. encryptioninfo <add key="DB1" value="mhu0VrvzBBlYjPbxh+EQk0zdY" /><add key="DB2" value="DVvHAq2EVKF5fmYYiUUJ/g==" />...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement