Hi Everybody,
Great script LucD...
I had some curious results returned on a few VMs.
Basically it looks like the get-stat returned an instance for a datastore that is not actually part of the VM.
That is the disk ID, naa.60060e801606400000010640023455601 for example, is returned by Get-Stats. This corresponds to datastore PROD-MGT-L001-NL7K, for example, which I can verify by looking at that datastore's properties, but if I do a get-datastore for the given VM, this datastore is not listed. The VM has no virtual disk on this datastore, there is no iso mapped to the CD-ROM drive from this datastore either. I thought perhaps it was historical data but even if I use the real time switch and get the stats from an hour ago, this disk still shows up as associated with the VMs. Quite puzzling. Anybody have any ideas on this?
Anyway I also fiddled with adding the VM's home clustername and primary portgroup name to the report using the following
$ClusterTab = @{}
$PortGroupTab = @{}
foreach($vm in $vms ){
$ClusterTab[$VM.name] = ($vm.vmhost.parent).name
$PGName = ($vm | Get-NetworkAdapter).networkname
If ($PGname.GetType().Name -eq "Object[]") {
$PortGroupTab[$VM.Name] = $PGName[0]
}
else {
$PortGroupTab[$VM.Name] = $PGName
}
}
Need to add the following to the New-Object properties hash list, and add the names to the output select property name list:
Cluster = $ClusterTab[$_.Values[0]]
PortGroup = $PortGroupTab[$_.Values[0]]
Also here is a way to add allocated diskspace aggregated per datastore for each VM.
But this can make the script take a while.
$DiskAllocTab = @{}
Foreach ($vm in $vms)
{
$DiskAllocTab[$vm.name] = @{}
foreach($ds in (Get-Datastore -VM $vm | where {$_.Type -eq "VMFS"}))
{
$DiskAllocTab[$vm.name][$ds.name] = @{}
$Alloc = (Get-HardDisk -VM $vm | where {$_.filename -like "*"+$ds.name+"*"} | Measure-Object -Sum CapacityGB).Sum
if ($Alloc) {
$DiskAllocTab[$vm.name][$ds.name] = $Alloc
}
else {
$DiskAllocTab[$vm.name][$ds.name] = 0
}
}
}
Add the following 3 lines to just before the New-object statement:
$DiskAllocGB = $null
Try {$DiskAllocGB = $diskAllocTab[$_.Values[0]][$lunTab[$_.Values[1]]]} Catch {$DiskAllocGB = 0}
if ($DiskAllocGB -eq $null) {$DiskAllocGB = 0}
Add the following line to the New-object property hash list:
DiskAllocGB = $DiskAllocGB
Then add the property name select statement for output.
DiskAllocGB
Cheers All!
If anybody has any idea why I get that weird anomaly of phantom datastores, drop a line here... I'm really stumped by it.
Garrett