1

I am trying to use Command or PowerShell to know where on a disk unallocated space is available.

For example below the unallocated space is present after G: drive (or Partition 1).

Using the command echo list disk | diskpart I can only know the Unallocated space.

enter image description here

Is there any way to know this information?

1
  • 2
    You can enumerate partitions via gwmi Win32_DiskPartition and detect the gaps by comparing StartingOffset property with an accumulated value of Size properties. Commented Aug 1, 2017 at 9:34

1 Answer 1

2

Solution for Windows 8/2012 Server or newer:

I think you could do this (needs to be run with Administrator rights) to return an object with each volume that can be extended (from which you can then deduce there is free space after the volume):

Get-Volume | Where DriveLetter -ne $null | ForEach-Object {
    $Size = Get-PartitionSupportedSize -DriveLetter $_.DriveLetter
    If ($Size.SizeMax -gt $_.Size) { $_ }
}
  • Get-Volume | Where DriveLetter -ne $null gets all drives that have a letter
  • $Size = Get-PartitionSupportedSize -DriveLetter $_.DriveLetter gets the sizemin and sizemax of each drive
  • If ($Size.SizeMax -gt $_.Size) { $_ } returns the volumes which can be extended (their size max is bigger than the current volume size).
Sign up to request clarification or add additional context in comments.

3 Comments

Powershell version is 2.0.. Looks like the above command runs on 3.0
@Chand It's not just PowerShell version, the Storage cmdlets weren't added until Server 2012/Win8.
I found a solution. Using starting and end address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.