How to get a list of VMs by Operating System that are on with Datastore usage and IP address in PowerCLI

This is a quick post to show an example of a script that will return a list of VMs by operating system that are on with datastore usage and IP address in PowerCLI

Connect-VIServer vcenter1

Connect-VIServer vcenter2

Connect-VIServer vcenter3

Connect-VIServer vcenter4

(Get-VM).where{$_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows'} |

Select Name,Notes,GuestID,@{N="IP Address";E={@($_.guest.IPAddress[0])}},
@{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},
@{N="UsedSpaceGB";E={[math]::Round($_.UsedSpaceGB,1)}},
@{N="ProvisionedSpaceGB";E={[math]::Round($_.ProvisionedSpaceGB,1)}},
@{N="Folder";E={$_.Folder.Name}} |
export-csv c:\temp\VMsOn.csv -nti 

Leave a Reply

Your email address will not be published. Required fields are marked *