【发布时间】:2021-09-28 08:41:31
【问题描述】:
我需要读取下面的 xml 文件并将其存储在哈希表中。
<?xml version="1.0"?>
<ConfigValues>
<Dev>
<item Key="dbconn" Value ="Data Source=xlvxdev.cumulus.com,1615;Initial Catalog=FPTR_XLVX;Security=true;"/>
</Dev>
<QA>
<item Key="dbconn" Value ="Data Source=xlvxqa.cumulus.com,1615;Initial Catalog=OPSR_CVRC;Security=true;"/>
</QA>
<PP>
<item Key="dbconn" Value ="Data Source=xlvxpreprd.cumulus.com,1615;Initial Catalog=OPSR_CVRC;Security=true;"/>
</PP>
<PROD>
<item Key="dbconn" Value ="Data Source=xlvxprd.cumulus.com,1615;Initial Catalog=OPSR_CVRC;Security=true;"/>
</PROD>
</ConfigValues>
我尝试在 powershell 下编写并能够获取属性键值,但我需要将其存储在哈希表中,以便我可以根据需要检索值。
$URLS = [xml](Get-Content 'C:\Desktop\Variables.xml')
$URLS.ConfigValues.Dev.item | where {$_.key -eq 'connCVRC'}
Key Value
--- -----
connCVRC Data Source=xlvxdev.cumulus.com,1615;Initial Catalog=FPTR_XLVX;Security=true;
【问题讨论】:
-
不太清楚你想要什么作为输出,是
$xml.ConfigValues.Dev.Item.Value.Split(';') | ConvertFrom-StringData吗?请在您的问题中添加预期结果。 -
感谢您与我联系。我正在寻找 mklement0 在以下答案中提供的相同结果
标签: powershell hashtable