Check the hyper-v vm's Maximum disk size

Copper Contributor

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.

6 Replies
Never have seen such an important comment @yiuyuxx235 xD

@zmmj123 

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}}

 

@zmmj123 

 

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

 

Many thanks for your help, I can use powershell comlet get the value now.