Hi,
As always, the forums here have provided me with what I need and I have learnt a huge amount. However my scripting knowledge is still not at a level where I can combine all I have learnt. I would really appreciate some assistance.
Basically, I would like to produce a report which shows each VM's disk configuration PLUS the size of committed disk if indeed the disk is Thin provisioned.
At present I have the following two pieces of code which work perfectly separately.
1st - Shows me the committed size
$report = @()
#$allvms = Get-VM
foreach ($vm in $allvms) {
$vmview = $vm | Get-View
foreach($disk in $vmview.Storage.PerDatastoreUsage){
$dsview = (Get-View $disk.Datastore)
$dsview.RefreshDatastoreStorageInfo()
$row = "" | select VMNAME, DATASTORE, VMSIZE_GB, VMUSED_GB, PERCENT
$row.VMNAME = $vmview.Config.Name
$row.DATASTORE = $dsview.Name
$row.VMSIZE_GB = (($disk.Committed+$disk.Uncommitted)/1024/1024/1024)
$row.VMUSED_GB = (($disk.Committed)/1024/1024/1024)
$row.PERCENT = [int](($row.VMUSED_GB / $row.VMSIZE_GB)*100)
$report += $row
}
}
$report | Out-GridView
2nd - Produces the bulk of the report
$report = @()
$report = foreach($vm in $ALLVMs) {
Get-HardDisk $vm | Select @{N="VM Name";E={$vm.Name}},
@{N="RDM Name";E={($_ | where {"RawPhysical","RawVirtual" -contains $_.DiskType}).FileName}},
@{N="Datastore Name";E={($_ | where {"RawPhysical","RawVirtual" -notcontains $_.DiskType}).Filename.Split(']')[0].TrimStart('[')}},
@{N="HD Name";E={$_.Name}},
@{N="HD Size GiB";E={$_.CapacityKB/1MB }},
@{N="Format";E={$_.StorageFormat }},
@{N="Disk committed";E={$_.Committed}},
@{N="Memory";E={ }},
Get-VM $vm | select @{N="Memory";E={$vm.MemoryMB}}
}
$report |Out-GridView
Thanks to those who submitted the above code, which I have altered somewhat!
Ideally, the 2nd report would contain a column "Disk committed" which shows the <committed> as per the 1st code.
Any help or pointers gladly accepted.