anyone have a script to query datastores to find out the VM and the hard disks it has with the format?
for example
VM, Hard Disk, DataStore Name, Type (format)
I would like to be able to run this by Datacenter and Cluster.
Is that possible?
Thanks
Hello, lorried82-
Sure is. Here's a snippet that uses the -PipelineVariable parameter available since PowerShell v4 to get such info:
Get-Datacenter -PipelineVariable oThisDatacenter | %{
## get all of the clusters in this datacenter
Get-Cluster -Location $oThisDatacenter -PipelineVariable oThisCluster | %{
## get all of the VMs in this cluster, and their HDisks
Get-VM -Location $oThisCluster | Get-HardDisk |
Select @{n="VM"; e={$_.Parent}},
@{n="HardDisk"; e={$_}},
@{n="Datastore"; e={$_.Filename.Split("]")[0].Trim("[")}},
StorageFormat,
@{n="Cluster"; e={$oThisCluster}},
@{n="DataCenter"; e={$oThisDatacenter}}
}
}
And, I added the Cluster and Datastore properties for each object, assuming that would be useful at some point. If not, just remove those items from the Select statement, of course. How's that do for you?
thanks Matt this looks great but I am not sure - what should I be changing here? Do I run this by cluster or datastore name?
Hello, lorried82-
Well, that depends upon the things upon which you want to report. As written, the code will:
If you wanted to narrow this down, you could add a datacenter name in the Get-Datacenter portion, or adjust it a bit to just report on a particular cluster (remove the Get-Datacenter portion altogether, and the DataCenter calculated property on the Select statement), and so on.
Is that helpful, or do you have a specific/different way in which you want to use the code?