VMware Cloud Community
Randy_B
Enthusiast
Enthusiast

List VM's and their OS

It's been a while since I took the PS class and I'm just not remembering how to put these things together. I'm trying to get a list of all the VM's in my VC and what OS they are running.

After running connect-vc, I can run get-vm | select-object name and get all the VM's fine. If I run Get-VMGuest -VM (Get-VM -Name "server1") I'll get the State, IP and OS of that vm. How do I put these together?

Thanks

Reply
0 Kudos
8 Replies
Randy_B
Enthusiast
Enthusiast

A little more playing with it and I answered my own question...

get-vmguest -vm (get-vm) | select-object vmname, osfullname | export-csv c:\vm_osreport.csv

Reply
0 Kudos
Ryan_1
Contributor
Contributor

get-vm|get-vmguest|format-list

gives enough info.

Reply
0 Kudos
LucD
Leadership
Leadership

You could combine these 2 cmlets this way

get-vm | %{
  $_ | select Name | Out-Default
  $_ | Get-VMGuest | select State, IPAddress, OSFullName | Out-Default
}

Now if you want the result in 1 object (or an array of objects) you could do

get-vm | %{
  $vm = "" | Select Name, State, IPAddress, OSFullname
  $vm.Name = $_.Name
  $guest = $_ | Get-VMGuest
  $vm.State = $guest.State
  $vm.IPAddress = $guest.IPAddress
  $vm.OSFullName = $guest.OSFullName  
  $vm
}


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

Reply
0 Kudos
Ryan_1
Contributor
Contributor

export-csv always displays the IP address as system.string[].

how to get the IP displayed in csv?

Reply
0 Kudos
yboychev
Hot Shot
Hot Shot

The reason is that the IPAddress of the vmguestInfo object is a stringArray even if it contains only 1 IP. When transfered to the csv the ToString() method is invoked therfore the result is system.string[].

Here is how you can avoid this:

 


get-vmguest -vm (get-vm)[0] | select-object vmname, osfullname, @{Name = "IPAddress"; Expression={foreach($address in $_.IPAddress){$address+=$address+ " ,"; return $address}}} | Export-CSV ... 


Yavor

Reply
0 Kudos
tigerdeccan
Enthusiast
Enthusiast

How to get the how much RAM allocated to the VM ?

Reply
0 Kudos
LucD
Leadership
Leadership

You can use the MemoryMB property.

Have a look at the VirtualMachine object in the PowerCLI Reference, it will show you all available properties.


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

Reply
0 Kudos
tigerdeccan
Enthusiast
Enthusiast

Hi LuCD,

Thanks

Mumtaz 

Reply
0 Kudos