VMware Cloud Community
foofighter26
Enthusiast
Enthusiast
Jump to solution

Export List of all VM's in Vcenter

Hi,

I am a complete amateur at scripting and new to PowerCLI. I am looking to export a list of all our virtual machines in our estate including the following values if possible:

Virtual Machine Name

Host the virtual machine is on

Notes

IP Address

regards,

Paul

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try this

Get-VM | select Name, Host, Description, @{N="IP"; E={$_ | Get-VMGuest | select -expandProperty IPAddress}}

Note: for the IP address you need to have the VMware Tools installed on the guest.


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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try this

Get-VM | select Name, Host, Description, @{N="IP"; E={$_ | Get-VMGuest | select -expandProperty IPAddress}}

Note: for the IP address you need to have the VMware Tools installed on the guest.


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

Reply
0 Kudos
aerodevil
Hot Shot
Hot Shot
Jump to solution

I'm not sure about the IP address but the following script will do the VMHost, VM, and Notes.

Connect-VIServer -Server server

$VMs = Get-VMHost

$myCol = @()

foreach($vmhost in $VMs){

$myObj = "" | Select-Object Name, VM, Notes

$myObj.Name = $vmhost.Name

$VM = $vmhost | Get-VM

foreach($vmguest in $VM){

$myObj.VM = $vmguest.Name

$myObj.Notes = $vmguest.Description

}

$myCol += $myObj

}

$myCol | Export-Csv "C:\VM_Notes.csv" -NoTypeInformation

Josh Atwell

Josh Atwell @Josh_Atwell http://www.vtesseract.com http://github.com/joshatwell/
aerodevil
Hot Shot
Hot Shot
Jump to solution

No Surprise...LucD's is better. Mine provides a little example on how to generate a collection and then export it which will come in handy for you someday I'm sure.

Josh Atwell

Josh Atwell @Josh_Atwell http://www.vtesseract.com http://github.com/joshatwell/
Reply
0 Kudos
foofighter26
Enthusiast
Enthusiast
Jump to solution

Thanks for that script it works perfectly! How would I tell it to output to an excel file?

Thanks,

Paul

Reply
0 Kudos
aerodevil
Hot Shot
Hot Shot
Jump to solution

end the oneliner by piping it into the Export-CSV cmdlet.

| Export-CSV "C:\filename.csv" -NoTypeInformation

Josh Atwell

Josh Atwell @Josh_Atwell http://www.vtesseract.com http://github.com/joshatwell/
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

True, but that won't work when a guest has more than 1 IP-address.

In that case the IP property will be an array which Export-Csv can't handle Smiley Sad


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

Reply
0 Kudos