XML and namespaces

This topic contains 3 replies, has 2 voices, and was last updated by  David Zemdegs 2 years, 4 months ago.

  • Author
    Posts
  • #25081

    David Zemdegs
    Participant

    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

  • #25082

    Rob Simmers
    Participant

    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:

  • #25106

    David Zemdegs
    Participant

    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

  • #25121

    David Zemdegs
    Participant

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

    Cheers
    David Z

You must be logged in to reply to this topic.