#1 14 Mar 2014 11:11

alwaysharsha
New Member
Registered: 14 Mar 2014
Posts: 1

Expand Hash variable while reading file content in PoSH 4.0

I have a xml file where i have defined some HashTable variables, when i read the content at runtime they should be resolved.


<variable>
    <clientname>$($hfinfo.hf)</clientname>
</variable>

It was working in the Powershell 2.0, the snippet is below.
PowerShell 2.0
--------------------
$hash=@{};
$hash.add("hf","HFDetail_Random_Name")

[xml]$xmlcontent=[xml]($ExecutionContext.InvokeCommand.ExpandString((Get-Content ($xmlFilePath))))

In powershell 4.0, when i execute the same command i am getting the error

Exception calling "ExpandString" with "1" argument(s): "Object reference not set to an instance of an object."

Thanks,
Harsha

Offline

Board footer

Powered by FluxBB