Thread: Processing XML
View Single Post
Old 10-21-2008   #2 (permalink)
RickB


 
 

Re: Processing XML

On Oct 21, 2:18*am, Jacob <jacob(AT)hfws.net.nospam> wrote:
Quote:

> I have the following script:
>
> Param(
> * * * $prefix,
> * * * $volumeTrustees
> * * * )
>
> #Load the Trustees files
> [xml]$trustees = get-content $volumeTrustees
>
> #Get all the Valid nodes
>
> $validNodes=$trustees.SelectNodes("//Path[starts-with(text(), '$prefix')]/..")
>
> $validNodes | ft
>
> The output is:
>
> subdirectory * * * * * * * * * * * * * */apps/Risk/Advisor Switchboard * * *
> * *{User, User, User, User...}
> subdirectory * * * * * * * * * * * * * */apps/softlogm * * * * * * * * * * *
> * *{User, User, User, User...}
> subdirectory * * * * * * * * * * * * * */apps/SuperReport * * * * * * * * * *
> * *{User, User, User, User}
> subdirectory * * * * * * * * * * * * * */apps/Risk/elmapp * * * * * * * * * *
> * *{User, User}
>
> And the input looks something like:
> <Path>/apps/ABC</Path>
> <User
> rights="_R____F_">.CN=GJudd.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</User*>
> <User
> rights="_RWC__F_">.CN=AUpchurch.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</*User>
> <User
> rights="_RWCEMF_">.CN=Everyone.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</U*ser>
> <User
> rights="_R____F_">.CN=RPhillips.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</*User>
> <User
> rights="_RWCEMF_">.CN=Maximus.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</Us*er>
> </Trustee_List>
> <Trustee_List type="subdirectory">
> <Path>/apps/ABC3</Path>
> <User
> rights="_RWCEMF_">.CN=Maximus.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</Us*er>
> <User
> rights="_RWCEMF_">.CN=TeamBMH.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</Us*er>
> </Trustee_List>
>
> My problem is I'd like to select each Path and then list all the 'User'
> nodes for that path. I can't help think there is a better way than using
> ForEach-object.
>
> --
> **********************
> Jacob

$validNodes|%{$t=$_.Path;$_.User|write-host $t,$_}

The key to nesting foreach pipelines (i.e. pipelines with %{}) is to
store the $_ value (or the part of it you need) in a temp variable
before creating the nested one. It's also possible to access the
parent scope of $_ but I usually consider that just too messy to
bother with.
My System SpecsSystem Spec