1
我正在嘗試使用PowerShell創建一個字典。以下是xml文件,將內部xml轉換爲PowerShell
和我正在下面的代碼,
$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/" />
我想包括在內部的XML部分字典。有人可以爲上述要求提出可能的解決方案嗎?
在此先感謝。
大。非常感謝。它按預期工作.. – mahesh