I was looking for a hint to get a quick view of VMs with their Datastore(s) details. For example I have list of VMs in a .csv file so I want to get view like that: VM+ datatores + capacity + free space
But so far I can only get VM + Datastore
$vmList=Get-Content "C:\Temp\VMs.csv"
$AllVMs = Get-VM $vmList
$MultVM=ForEach ($VM in $AllVMs){ Get-View -ViewType VirtualMachine -filter @{"Name"="$VM"} -Property "Name", "Config.DatastoreUrl"}
$MultVM | Select-Object -Property Name, @{N="DataStore";E={$_.Config.DatastoreUrl | %{$_.Name}}}
Name DataStore
---- ---------
vm01 Datastore-LUN03
vm02 Datastore-LUN07
vm03 Datastore-LUN08
Thanks.
Try something like this
$vmList=Get-Content "C:\Temp\VMs.csv"
$filter = ($vmList) -join '|'
$props = 'Name','Storage.PerDatastoreUsage'
foreach($vm in (Get-View -ViewType VirtualMachine -filter @{"Name"=$filter} -Property $props)){
$vm.Storage.PerDatastoreUsage |
Select @{N='VM';E={$vm.Name}},
@{N='Datastore';E={($script:ds = Get-View -Id $_.Datastore -Property Name,Summary).Name}},
@{N='DSCapacityGB';E={[math]::Round($script:ds.Summary.Capacity/1GB)}},
@{N='DSFreeGB';E={[math]::Round($script:ds.Summary.FreeSpace/1GB)}},
@{N='DSUsedForVMGB';E={[math]::Round($_.Committed/1GB)}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
$vmList=Get-Content "C:\Temp\VMs.csv"
$filter = ($vmList) -join '|'
$props = 'Name','Storage.PerDatastoreUsage'
foreach($vm in (Get-View -ViewType VirtualMachine -filter @{"Name"=$filter} -Property $props)){
$vm.Storage.PerDatastoreUsage |
Select @{N='VM';E={$vm.Name}},
@{N='Datastore';E={($script:ds = Get-View -Id $_.Datastore -Property Name,Summary).Name}},
@{N='DSCapacityGB';E={[math]::Round($script:ds.Summary.Capacity/1GB)}},
@{N='DSFreeGB';E={[math]::Round($script:ds.Summary.FreeSpace/1GB)}},
@{N='DSUsedForVMGB';E={[math]::Round($_.Committed/1GB)}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That simple! This is amazing! Thank you sir!
One more thing, it is showing only where VMX file located, what if VM has disks located on multiple datastores?
The PerDatastoreUsage property has entries for each datastore where the VMhas files.
So they should all show.
Did you see the contrary?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not showing the second disk. Here is what I see with old script :
Name Value
---- -----
tic-vm01 {Datastore-LUN03, Datastore-LUN07}
tic-vm02 Datastore-LUN08
tic-vm03 Datastore-LUN08
And this is with new:
VM : tic-vm01
Datastore : Datastore-LUN03
DSCapacityGB : 4096
DSFreeGB : 2052
DSUsedForVMGB : 104
VM : tic-vm02
Datastore : Datastore-LUN08
DSCapacityGB : 4096
DSFreeGB : 3249
DSUsedForVMGB : 423
VM : tic-vm03
Datastore : Datastore-LUN08
DSCapacityGB : 4096
DSFreeGB : 3249
DSUsedForVMGB : 423
Seems to be working for me, are you sure you are running the script exactly as I posted above?
Don't mind the numbers, these are Thin provisioned HD
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I do not get, it works for one VC but not for another one. It is very strange -same version, same build number O_O
I will try on another 2 VCs
It seems like only works for one VC out 4. For 3d one it returns 4th VM that is not even in the file. For first VM it is not showing second disk. It is really wired
I figured out the issue. It looks like a PCLI v.6.5.1 issue (bug?), I did update it to 6.5.4 and now it is showing all disks. But for one VC I see an extra VM. I suspect it is because the VM was renamed and initially had same name as another one in the list. Anyway thanks again for the help! You are the best!
Thanks.
You sure that VM is not a Templae?
With Get-View -ViewType VirtualMachine you also get the Templates.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It is a VM (| Where {
-not
$_
.Config.Template}
), but it is not that big issue, in this case more information is better than less
Thanks again!