![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Processing XML 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.</User> <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.</User> </Trustee_List> <Trustee_List type="subdirectory"> <Path>/apps/ABC3</Path> <User rights="_RWCEMF_">.CN=Maximus.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</User> <User rights="_RWCEMF_">.CN=TeamBMH.OU=AllStaff.OU=BRIS.O=BDOK.T=BDOKENDALLS.</User> </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 |
My System Specs![]() |
| | #2 (permalink) |
| Guest | 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 Specs![]() |
| | #3 (permalink) |
| Guest | Re: Processing XML RickB wrote: Quote: > $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. foreach ( $node in $validNodes ) { $node.User | % { $node.Path, $_ } } is one example... -- $signature = "Hal Rottenberg, MVP - Admin Frameworks" $projects = @{ title = "Blog Author"; url = "http://halr9000.com" }, @{ title = "Co-host"; url = "http://powerscripting.net" }, @{ title = "Community Director"; url = "http://PowerShellCommunity.org" }, @{ title = "Psi Webmaster"; url = "http://psi-im.org" } |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Processing XML Thanks guys that did the trick. -- ********************** Jacob "Hal Rottenberg [MVP]" wrote: Quote: > RickB wrote: Quote: > > $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. > Or you can use Foreach-the-Statement (not foreach-object-the-cmdlet): > > foreach ( $node in $validNodes ) { $node.User | % { $node.Path, $_ } } > > is one example... > > -- > $signature = "Hal Rottenberg, MVP - Admin Frameworks" > $projects = @{ title = "Blog Author"; url = "http://halr9000.com" }, > @{ title = "Co-host"; url = "http://powerscripting.net" }, > @{ title = "Community Director"; url = "http://PowerShellCommunity.org" }, > @{ title = "Psi Webmaster"; url = "http://psi-im.org" } > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| More processing power | General Discussion | |||
| Log In Out File Processing | PowerShell | |||
| Asynchronous Processing | PowerShell | |||
| More text processing. | PowerShell | |||
| Event Log taking up all my processing | Vista performance & maintenance | |||