Author Posts

May 7, 2014 at 4:17 pm

All, new at all the scripting things and I am missing a basic step I hope you can clue me in on. I am using VmWare Powercli, but I am 99% sure this is basic Powershell that applies to all users.

So this line :

get-cluster "Cluster" | Get-VM | select-object name, vmhost, folder

Returns me a nice little output of the data I want, like this

Name VMHost Folder
—- —— ——
P-SPAPP02 esx0315-mgmt Sharepoint
p-netops02 esx0315-mgmt NetOps
P-LyncSQL01 esx0315-mgmt Lync

And this returns some nice, pretty information as well.

get-cluster "Cluster" | Get-VM | get-networkadapter | select-object networkname

NetworkName
———–
Corporate Network
VM Production
MSCS Private Network

What is the easy, simple way to combine the two commandlets to that my final output is this:

Name VMHost Folder NetworkName
—- —— —— ———–
P-SPAPP02 esx0315-mgmt Sharepoint Corporate Network
p-netops02 esx0315-mgmt NetOps VM Production
P-LyncSQL01 esx0315-mgmt Lync MSCS Private Network

Thanks for your help....

May 7, 2014 at 4:55 pm

This is written without being able to test it, so there might of course be a spelling error or two, but I believe something along the lines of the following should work:

Get-Cluster "Cluster" | Get-VM | Select Name, VMHost, Folder, @{ Name= 'NetworkName', Expression = { $_ | Get-NetworkAdapter | Select -Expand NetworkName }}