-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-disk-expand-windows.ps1
33 lines (27 loc) · 1021 Bytes
/
vm-disk-expand-windows.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
param([switch]$Elevated)
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated) {
# tried to elevate, did not work, aborting
} else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
'running with full privileges'
Update-HostStorageCache
foreach($disk in Get-Disk)
{
# Variable specifying the drive you want to extend
$drives=(Get-Partition -DiskNumber $disk.Number | where {$_.DriveLetter}).DriveLetter
# Script to get the partition sizes and then resize the volume
$drive_letter=""
foreach($drive in $drives){
$drive_letter=$drive
}
$size = (Get-PartitionSupportedSize -DriveLetter $drive_letter)
Resize-Partition -DriveLetter $drive_letter -Size $size.SizeMax
}