PowerShell: Expand Disk Volume to Maximum Size


function expandDiskMaxSize($driveLetter='c'){    
        $existingSize=(Get-Partition -DriveLetter $driveLetter).Size
        $max=(Get-PartitionSupportedSize -DriveLetter $driveLetter).SizeMax
        if($existingSize -lt $max){
            write-host "Resizing volume driver letter '$driveLetter' to its available maximum of $([math]::round($max/1GB))GB"
            Resize-Partition -DriveLetter $driveLetter -Size $max -ea Stop
            write-host "Volume driver letter '$driveLetter' is not less than its available maximum of $([math]::round($existingSize/1GB))GB. Volume not resized."
        return $true
        write-warning $_
        return $false

expandDiskMaxSize $driveLetter

Leave a Reply

Your email address will not be published. Required fields are marked *