Extend volumes with free space using Powershell and Diskpart

后端 未结 3 1967
醉酒成梦
醉酒成梦 2021-01-24 01:19

All of our servers are getting their Disk allocations increased. I have no desire to type:

Select disk 6
Select Partition 1
Extend
Select disk 7
Select Partitio         


        
3条回答
  •  迷失自我
    2021-01-24 02:06

    Same solution but more simple, and it works with other locales too:

    function Extend-Partition($disk, $part)
    {
      "select disk $disk","select partition $part","extend" | diskpart | Out-Null
    }
    
    $disks = ((wmic diskdrive get Index | Select-String "[0-9]+") -replace '\D','')
    
    ForEach ($disk in $disks) {
    
        $parts = ((wmic partition where DiskIndex=$diskId get Index | Select-String "[0-9]+") -replace '\D','' | %{[int]$_ + 1})
    
        ForEach ($part in $parts) {
            Extend-Partition $disk $part
        }
    }
    

提交回复
热议问题