VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Accessing members

Have a simple syntax question:

I get a VM as follows:

get-vm vmname

then somewhere farther down the pipe I want to look at one of this object's members such as "guest".  How do I reference the object that is currently coming down the pipeline such as in the example below

get-vm vmname | [reference the current VM object].guest

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The % is used as an alias for the ForEach-Object cmdlet.

You can see all aliases with

Get-Alias


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
6 Replies
chriswahl
Virtuoso
Virtuoso
Jump to solution

If you encase the command in parethesis, you can reference further items without piping.

For example, to see the name of the guest OS

(Get-VM vmname).guest.osfullname

With piping, I would express it as:

Get-VM vmname | select Name,@{N="OS Name";E={$_.Guest.OSFullName}}

Great reference site: http://www.lucd.info/

VCDX #104 (DCV, NV) ஃ WahlNetwork.com ஃ @ChrisWahl ஃ Author, Networking for VMware Administrators
TheVMinator
Expert
Expert
Jump to solution

Get-VM vmname | select Name,@{N="OS Name";E={$_.Guest.OSFullName}}

OK thanks.  However, it seems that there must be a simpler expression than this.   Isn't there a single or double-character operator that can be used to reference the current object, and then access that object's members, such as:

get-vm vmname | $_.guest

It seems that I have seen / used something like this but can't remember how to do it.

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you mean ?

Get-VM | %{$_.Guest}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

TheVMinator
Expert
Expert
Jump to solution

That's it - thanks again.  Got tripped up on the modulus operator (%) being used also in that context.  Why is it required?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The % is used as an alias for the ForEach-Object cmdlet.

You can see all aliases with

Get-Alias


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

Thanks again Luc

Reply
0 Kudos