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
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
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/
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
That's it - thanks again. Got tripped up on the modulus operator (%) being used also in that context. Why is it required?
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
Thanks again Luc