Windows Vista Forums

Searching for XML Elements

  1. #1


    sferrier@gmail.com Guest

    Searching for XML Elements

    Hello,

    First, allow me to explain that I am a newb to PoSH, .NET, and
    processing XML altogether, so apologise in advance for such basic
    questions. I'm coming straight from VB6/VBScript to all of this
    wonderful new stuff, and it's all a bit overwhelming.

    In any event, hoping that someone can assist. I took a copy of
    Microsoft's CreateXMLFromEnvironment.wsf from the Group Policy
    Management Console, modified it slightly such that it outputs Group
    Policy GUIDs, and am looking for a way to create a PS1 to query all of
    the unique GUIDs contained therein. The XML structure looks something
    like this:

    <DomainRoot>
    <OU Name="OUName1">
    <OU Name="OU2">
    <GPOLink GPOName="Policy1" GUID="abcdefg1">
    <OU Name="OU3">
    <GPOLink GPOName="Policy2" GUID="abcdefg2">
    </OU>
    </OU>
    </OU>
    </DomainRoot>

    So, in other words, the GPOLink attribute can exist anywhere in the
    tree, and it might or might not be present.

    I've been trying things like get-childitem such that I might create a
    recursive function, but so far that hasn't gotten my anywhere. Also
    tried... think it was maybe sort-object -unique? Can't remember off
    hand. Anyway, that got me nowhere either. Tried enumerating child
    objects using the XML .get_firstchild and others, and got stuck on
    those too. If I could write this in SQL, could figure it out, but this
    syntax is killing me. And how do you get help on the methods defined
    in the System.Xml.XmlLinkedNode objects?

    Hoping that someone can give me a clue.

    Thanks,
    Shawn.


      My System SpecsSystem Spec

  2.   


  3. #2


    Keith Hill Guest

    Re: Searching for XML Elements

    <sferrier@gmail.com> wrote in message
    news:1174525453.049237.7360@d57g2000hsg.googlegroups.com...
    > Hello,
    >
    > First, allow me to explain that I am a newb to PoSH, .NET, and
    > processing XML altogether, so apologise in advance for such basic
    > questions. I'm coming straight from VB6/VBScript to all of this
    > wonderful new stuff, and it's all a bit overwhelming.
    >
    > In any event, hoping that someone can assist. I took a copy of
    > Microsoft's CreateXMLFromEnvironment.wsf from the Group Policy
    > Management Console, modified it slightly such that it outputs Group
    > Policy GUIDs, and am looking for a way to create a PS1 to query all of
    > the unique GUIDs contained therein. The XML structure looks something
    > like this:
    >
    > <DomainRoot>
    > <OU Name="OUName1">
    > <OU Name="OU2">
    > <GPOLink GPOName="Policy1" GUID="abcdefg1">
    > <OU Name="OU3">
    > <GPOLink GPOName="Policy2" GUID="abcdefg2">
    > </OU>
    > </OU>
    > </OU>
    > </DomainRoot>


    Welcome to wonderful world of PowerShell. :-)

    PowerShell has pretty decent native support for XML. For example you can
    create a .NET XML object by just casting a string (or array or strings) to
    [xml] like so (assuming the string represents valid XML):

    $xml = [xml](get-content guid.xml)

    Now you can do stuff like this:

    $xml.DomainRoot.OU.OU

    Name GPOLink
    OU
    ---- -------
    --
    OU2 GPOLink
    OU

    That is the XML elements show up as properties on the PowerShell xml
    objects. You can also access the .NET XML methods one of which is the very
    handy SelectNodes() which takes an XPath expression. So you could pretty
    easily do what you want with this:

    $xml = [xml](get-content guid.xml)
    $xml.SelectNodes('//@GUID') | sort #text -uniq

    Where #text represents the text value of the GUID attribute.

    --
    Keith


      My System SpecsSystem Spec


Searching for XML Elements
Similar Threads
Thread Forum
Adobe Photoshop Elements 6 & Adobe Premiere Elements 4 Vista music pictures video
Can't delete elements in folder Recent elements Vista General
Elements 6 No Cd Rom Drivers
Support for Adobe photoshop elements 5 or premier elements 3 on Vista 64 bits Vista General
Adobe Elements 5.0 Vista General