- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following script executes and provides what was desired - though there are a few tweeks I would like to impose -
1. One key tweek is how to get the output csv file to include the source path and file name of the executed script
2. In the situations where I am looking at a snapshot existing I would also like to get the base file size for the vmdks. For some reason - the report kills the file size on the base vmdk's when discovering snapshots almost like it is pulling the information from the config file instead of raw off the disk. JUST ADDING A FOOTNOTE: I noted that when there is a snapshot on the system, the VMDK size is reported as zero - which of course is incorrect. So, I'm asking Luke or anyone who can, to tell me what is wrong. I suspect it is because the extensiondata.name is changed when a snapshot is ran, and the config file is no longer pointed to the Flat file - but my knowledge of the extensiondata is weaker that it should be and I don't really know all the SDK content that lets me drill down to the specifics without a lot more coding. I have included a copy of the output and the latest version of my PS1. Anyone who can point me to better guidance on the extensiondata and how to pull the fine details from it will be very much appreciated.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) { ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) { ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) { ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name )) { $SnapSize=Get-Snapshot -VM $VM | Measure-Object -Property SizeGB -Sum "" | Select-Object -Property @{N="VM";E={$VM.Name}}, @{N="Datacenter";E={$Datacenter.name}}, @{N="Folder";E={$VM.Folder}}, @{N="Host";E={$VM.VMHost}}, @{N="Cluster";E={$Cluster.Name}}, @{N="# CPU";E={$VM.NumCpu}}, @{N="RAM";E={$VM.MemoryGB}}, @{N="IP";E={$VM.Guest.IPAddress}}, @{N="Hard Disk";E={$HardDisk.Name}}, @{N="HD Size";E={$HardDisk.CapacityGB}}, @{N="HD Type";E={$HardDisk.StorageFormat}}, @{N="Snap Size";E={$SnapSize.Sum}}, @{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}}, @{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}}, @{N="VMDKpath";E={$HardDisk.FileName.Split("]")[1]}} } } } }$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path $path
Message was edited by: MD4SV