powershell - Find XML attributes at random -


how can find 2 attributes $_.completename , $_.channel @ random?

+ $channel | ? {$liste} | get-random <<<<  -min 0 -max $liste.list.groupe.count     + categoryinfo          : invalidargument: (position:psobject) [get-random     ], parameterbindingexception     + fullyqualifiederrorid : inputobjectnotbound,microsoft.powershell.command     s.getrandomcommand 

sample data

$xliste = [xml]@" <list>    <groupe>         <position type="general">             <completename>folder-1</completename>             <dateyy>2014</dateyy>             <datemm>jaenner</datemm>             <datedd>mittwoch</datedd>             <overall_mode>cbr</overall_mode>             <duration>00:1:27</duration>             <overall_rate>96.0kbps</overall_rate>         </position>         <position type="version">             <channel>channel2</channel>             <codecid>55</codecid>             <duration>00:1:27</duration>             <compression>lossy</compression>             <streamsize>96.0kbps</streamsize>         </position>     </groupe>     <groupe>         <position type="general">             <completename>folder-2</completename>             <dateyy>2013</dateyy>             <datemm>maerz</datemm>             <datedd>montag</datedd>             <overall_mode>cbr</overall_mode>             <duration>00:8:12</duration>             <overall_rate>96.0kbps</overall_rate>         </position>         <position type="version">             <channel>channel1</channel>             <codecid>49</codecid>             <duration>00:8:12</duration>             <compression>lossy</compression>             <streamsize>96.0kbps</streamsize>         </position>     </groupe> </list> "@ 

code

$channel_and_completename = select-xml $liste -xpath "*/*/*" | select-object -expand node | ? {$_ -ne ($_.completename)+" "+($_.channel)} $channel_and_completename | ? {$liste} | get-random -min 0 -max $liste.list.groupe.count 

still not clear looking take xml , select, @ random, 1 of channel , completename pairings custom object

$xliste.list.groupe | foreach-object{     $props = @{}     $_.position | foreach-object{             if($_.type -eq "general"){             $props.completename =  $_.completename         } elseif($_.type -eq "version"){             $props.channel =  $_.channel         }     }     new-object -typename pscustomobject -property $props  } | get-random 

sample output

completename channel  ------------ -------  folder-1     channel2 

pure string based output

$xliste.list.groupe | foreach-object{     $string = @()     $_.position | foreach-object{             if($_.type -eq "general"){             $string +=  $_.completename         } elseif($_.type -eq "version"){             $string +=  $_.channel         }     }     $string -join "`t" } | get-random  

output

folder-2    channel1 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -