我有一个 xml 文件,我在其中定义了一些 HashTable 变量,当我在运行时读取内容时,它们应该被解析。
XML 文件
<variable>
<clientname>$($hfinfo.hf)</clientname>
</variable>
它在 Powershell 2.0 中运行,代码片段如下。
PowerShell 2.0
$hash=@{};
$hash.add("hf","HFDetail_Random_Name")
[xml]$xmlcontent=[xml]($ExecutionContext.InvokeCommand.ExpandString((Get-Content ($xmlFilePath))))
电源外壳 4.0
在 PoSH 4.0 中,当我执行相同的命令时,我得到了错误
Exception calling "ExpandString" with "1" argument(s): "Object reference not set to an instance of an object."