May 11 2021 06:42 PM
Hi all, In vm's setup, in SCSI controller, in virtual hard disk, and click "inspect" botten, I can see the "Maximum disk size". Now I want to use powershell commandlet to check this value, please help to check which command can get this value. Many thanks.
May 14 2021 12:40 PM
May 16 2021 04:25 PM
Get-VHD is the command you want to use specifying the path to the VHD. ensure that you use administrative PowerShell console as running as standard account is unlikely to have the correct permissions within Hyper-V.
FileSize will give you the current size of the VHD for dynamic disks and Size gives you the configured maximum VHD size - you will need to convert the values into GB. see example below
Get-VHD -Path "C:\Hyper-V\Virtual Hard Disks\abc.vhdx" | Select-Object @{Name="FileSizeGB";Expression={$_.FileSize/1GB}}, @{Name="MaxSizeGB";Expression={$_.Size/1GB}}
May 16 2021 05:46 PM
You can also expand this out to list for all VHDX files under a given location as well using this script, which will give you the VHDName FileSize and MaxSize
$vhds = Get-ChildItem -path C:\Hyper-V\ -filter *.vhdx -Recurse | Select-Object Name, Directory
$results =@()
ForEach ($vhd in $vhds){
$vpath = "$($vhd.Directory)" + "\" + "$($VHD.Name)"
$results += Get-VHD -Path $vpath | Select-Object @{Name="VHDName";Expression={$_.Path.split("\")[-1]}} , @{Name="FileSize_GB";Expression={$_.FileSize/1GB}} , @{Name="MaxSizeGB";Expression={$_.Size/1GB}}
}
$results | Format-Table
May 16 2021 11:44 PM