Monday, 3 March 2014

Quick VM report - IPs and (vcloud vapp or VM folder)

Its been a while since I blogged anything, so even though this isn't much to write home about, the end of my project and therefore the need for a new job has inspired me to blog this :)

Today I needed to get a list of all VMs in a VDC (which translates to vsphere as a resource group).

The resource group name is hard-coded below as CHANGME, so you need to update this ;)

ipreport.ps1 begins;

#Connect to vcenter
connect-viserver

#create a report shell
$table = @()

#GetVM Name and IP address
get-resourcepool CHANGME | get-vm | foreach {

#Create row
$vminfo = "" | select-object Name,IPAddress,vapp
#Populate row's column with VM name
$vminfo.name = $_.name
#Populate row's column with IP address
$vminfo.IPAddress = $_.guest.extensiondata.IPAddress
#Populate row's column with vapp name
$vminfo.vapp = $_.folder
#Commit row to the report
$table += $vminfo
}

#Pipe report through a sort command, and output to HTML for easy reading
$table | sort-object -property IPaddress | convertto-html -title "IPs for VMs" > C:\scripts\ips.html

No comments:

Post a Comment