Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Searching for XML Elements

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-21-2007   #1 (permalink)
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
Old 03-21-2007   #2 (permalink)
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
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adobe Photoshop Elements 6 & Adobe Premiere Elements 4 Jorge131 Vista music pictures video 12 05-27-2008 08:54 PM
Can't delete elements in folder Recent elements Gudmund Liebach Nielsen Vista General 1 05-05-2008 07:17 PM
Elements 6 No Cd Rom BPALMER Drivers 3 01-01-2008 07:19 PM
Support for Adobe photoshop elements 5 or premier elements 3 on Vista 64 bits Sébastien DELAYRE Vista General 5 03-26-2007 09:57 AM
Photo Elements 5 will_s Vista General 0 11-05-2006 02:48 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51