Author Posts

May 11, 2015 at 4:38 am

Greetings,
I have navigated my first XML Powershell experience recently with no problem. It features a no namespace xml file and I have mastered xpath to get me anywhere I wish.
Today I ran get-gporeport to produce an xml file with every gpo. I thought I could do my selectnodes and select-xmls with ease. Sadly nothing happened. Google told me about namespaces.
It said, If you dont define namespaces, you cannot read a thing, you cannot dance the xml element search and retrieve.
What's worse, google has next to nothing about bulletproof "just run this boilerplate code and then you can do selectnodes etc without a problem".
So either I run through the text of my huge gpo xml file and pull out all this xmlns garbage or define some namespace object that will allow me to xpath with ease.
Has anyone got any decent reference or best practice, particularly with reference to the xml produced by get-gporeport?
I tried the code at [url]http://outputredirection.blogspot.com.au/2010/01/using-powershell-to-search-for-group.html[/url] and it didnt work.

Thanks
David Z

May 11, 2015 at 5:08 am

A quick search and I found this:

http://blogs.technet.com/b/heyscriptingguy/archive/2013/02/07/use-powershell-to-generate-and-parse-a-group-policy-object-report.aspx

Depending on what data you are looking for, Get-GPO will show you information in a standard Powershell format: See these methods as well:

Managing Group Policy with PowerShell

May 11, 2015 at 12:31 pm

Thanks – I saw those. None of those still have the magic code to unlock xml searching by creating the necessary namespaces. The first post I mentioned does, but it doesnt work when I try it.

Cheers
David

May 12, 2015 at 3:13 am

I found a function on poshcode to remove xml namespaces. Worked a treat.
Its here: http://poshcode.org/1492

Cheers
David Z