One if the category of ‘useful PowerShell one-liners’… getting the maximum size of dynamic VHD’s:
Get-VirtualHardDisk -VMMServer SCVMM | Select-Object @{Label=”Name”;Expression={$_.Name}},@{Label=”VHD Maximum Size”;Expression={[Math]::Truncate(($_.MaximumSize-$_.Size) / 1GB)}} | Where-Object {($_.VHDType -Match “DynamicallyExpanding” -And $_.Name -NotMatch “{“)} | Export-Csv DynamicVHDSizes.csv
This will provide an output like the following:
I found this very handy when calculating if the available storage has been over subscribed
But let’s go a little bit further… some time ago I wrote a post about getting the available amount of space within dynamic VHD files. What if we were to combine that script with the one above?
Then we would get the amount of increase in storage usage when converting your dynamic VHD’s into static VHD’s
Here we go:
Get-VirtualHardDisk -VMMServer SCVMM | Select-Object @{Label=”Name”;Expression={$_.Name}},@{Label=”Current Size”;Expression={[Math]::Truncate($_.Size / 1GB)}},@{Label=”VHD Maximum Size”;Expression={[Math]::Truncate(($_.MaximumSize-$_.Size) / 1GB)}} | Where-Object {($_.VHDType -Match “DynamicallyExpanding” -And $_.Name -NotMatch “{“)} | Export-Csv PrepareVHDConversion.csv
And this will provide an output like: