Hello all, I have a question for ya, it is more of a powershell question but this group is good. When I look through a object I want the object reference and the value, somthing like this;
$a = @()
$t = "" | select first, last, email
$t.first = "Tom"
$t.last = "Jones"
$t.email = "tom@jones.com"
foreach($view in $t){
$view
}
This will get me the answers, I want the answer (Tom) and the reference (first). Can this be done?
Thank you,
Tim
Ok, got it.
Perhaps not most elegant solution for this, but it should do the trick
$a = "" | select Field1, Field2 $a.Field1 = "abc" $a.Field2 = 111 $t = $a | gm -memberType NoteProperty for($i=0; $i -lt $t.Count; $i++){ $name = $t[$i].Name Write-Host $name "=" $a."$name" }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm not sure I understand what you want to see on the screen.
Could you perhaps show a line like the output should appear ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
foreach($view in $t){
Tom
Jones
Tom@jones.com
}
How can I show somthing like this
foreach($view in $t){
first = Tom
last = Jones
email = Tom@jones.com
}
Tim
Ok, got it.
Perhaps not most elegant solution for this, but it should do the trick
$a = "" | select Field1, Field2 $a.Field1 = "abc" $a.Field2 = 111 $t = $a | gm -memberType NoteProperty for($i=0; $i -lt $t.Count; $i++){ $name = $t[$i].Name Write-Host $name "=" $a."$name" }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you, that will do.