VMware Cloud Community
timgerr
Contributor
Contributor
Jump to solution

More of a powershell question but you all are great

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
timgerr
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
timgerr
Contributor
Contributor
Jump to solution

Thank you, that will do.

0 Kudos