AnsweredAssumed Answered

Powershell code to read users.xml file?

Question asked by Mark Landin on May 21, 2018

Would like to read through our relatively large users.xml file and extract standalone license assignments to machine names. I'm doing this with Powershell, which makes working with XML files "easy" ... but I'm having some difficulty since the users.xml file uses a namespace and that complicates things. I'm trying to use sample code I've found in numerous places around the net, but not having much luck getting actual results.

 

Here's what I'm trying:

[xml]$list = Get-Content c:\scratch\sw\users-slc.xml

$ns= New-Object System.Xml.XmlNamespaceManager($list.NameTable)

$ns.AddNamespace("ns", $network.DocumentElement.NamespaceURI)


$list.SelectSingleNode("//ns:UserName[@name='SLC-DMXL3371QZV']", $ns)

 

 

The contents of $list after this are:

 

 

xml                             AdminDirectorUsers

---                             ------------------

version="1.0" encoding="UTF-16" AdminDirectorUsers

 

I'm not very savvy with XML files and namespaces so I'm kinda flailing around in the dark. Anybody with any suggestions?

Outcomes