Check the hyper-v vm's Maximum disk size

%3CLINGO-SUB%20id%3D%22lingo-sub-2347313%22%20slang%3D%22en-US%22%3ECheck%20the%20hyper-v%20vm's%20Maximum%20disk%20size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2347313%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%20In%20vm's%20setup%2C%20in%20SCSI%20controller%2C%20in%20virtual%20hard%20disk%2C%20and%20click%20%22inspect%22%20botten%2C%20I%20can%20see%20the%20%22Maximum%20disk%20size%22.%20Now%20I%20want%20to%20use%20powershell%20commandlet%20to%20check%20this%20value%2C%20please%20help%20to%20check%20which%20command%20can%20get%20this%20value.%20Many%20thanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2347313%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2347323%22%20slang%3D%22en-US%22%3ERe%3A%20Check%20the%20hyper-v%20vm's%20Maximum%20disk%20size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2347323%22%20slang%3D%22en-US%22%3Enice%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2356102%22%20slang%3D%22en-US%22%3ERe%3A%20Check%20the%20hyper-v%20vm's%20Maximum%20disk%20size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2356102%22%20slang%3D%22en-US%22%3ENever%20have%20seen%20such%20an%20important%20comment%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1051525%22%20target%3D%22_blank%22%3E%40yiuyuxx235%3C%2FA%3E%20xD%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2359399%22%20slang%3D%22en-US%22%3ERe%3A%20Check%20the%20hyper-v%20vm's%20Maximum%20disk%20size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2359399%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1048913%22%20target%3D%22_blank%22%3E%40zmmj123%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-VHD%20is%20the%20command%20you%20want%20to%20use%20specifying%20the%20path%20to%20the%20VHD.%20ensure%20that%20you%20use%20administrative%20PowerShell%20console%20as%20running%20as%20standard%20account%20is%20unlikely%20to%20have%20the%20correct%20permissions%20within%20Hyper-V.%3C%2FP%3E%3CP%3EFileSize%20will%20give%20you%20the%20current%20size%20of%20the%20VHD%20for%20dynamic%20disks%20and%20Size%20gives%20you%20the%20configured%20maximum%20VHD%20size%20-%20you%20will%20need%20to%20convert%20the%20values%20into%20GB.%20see%20example%20below%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-VHD%20-Path%20%22C%3A%5CHyper-V%5CVirtual%20Hard%20Disks%5Cabc.vhdx%22%20%7C%20Select-Object%26nbsp%3B%40%7BName%3D%22FileSizeGB%22%3BExpression%3D%7B%24_.FileSize%2F1GB%7D%7D%2C%20%40%7BName%3D%22MaxSizeGB%22%3BExpression%3D%7B%24_.Size%2F1GB%7D%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New 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.