0

PowerCli – List of Tagged VMs, Datastore and Host

Here is a relatively simple PowerCli one liner that will list the virtual machines based on a VM Tag assigned to them, along with the Datastore(s) that the VM is on and the Host that the VM is currently on.

The example below assumes that there is a tag with ‘Test/Dev’ in it assigned to the VMs (but this can be changed to whatever you wish), the other item to change would be the exportfolderlocation.

$test = get-vm -tag *Test/Dev* | Select Name, @{N="Datastore";E={[string]::Join(',',(Get-Datastore -Id $_.DatastoreIdList | Select -ExpandProperty Name))}},@{N="Folder";E={$_.Folder.Name}},VMHost | Export-Csv exportfolderlocation\Test.csv -NoTypeInformation -UseCulture

Leave a Reply

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