Reputation: 788
Handle the PSObject in C# For command :
Get-SCVirtualNetworkAdapter -All
One of the Response Object :
IPv4Addresses : {12.12.12.12}
Serialized data :
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>Deserialized.System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]</T>
<T>Deserialized.System.Object</T>
</TN>
<LST>
<S>192.168.11.22</S>
</LST>
</Obj>
</Objs>
I want to get the
<LST>
<S>192.168.11.22</S>
</LST>
as
List<String>
Upvotes: 0
Views: 864
Reputation: 11055
You can use any xml parser for this. I will prefer linq to xml.
var xml=XElement.Load(xmlFilePath);
var nsManager=new XmlNamespaceManager(new XmlNameTable());
nsManager.AddNamespace("ns1",@"http://schemas.microsoft.com/powershell/2004/04");
var list=xml.XPathSelectElements("//ns1:LST/ns1:S",nsManager)
.Select(element=>element.Value);
PS: You need to add System.Xml
,System.Xml.Linq
and System.Xml.XPath
namespaces in the using
statements.
Upvotes: 1