Option 1: Expanding disk of a Virtual Machine in Hyper-V
# ExpandVolumeVirtualFileServerRole.ps1
# Update these variables
$fileServerRole="APP008"
$driveLetter="D"
# Locate the host for the file server role
$roleOwner=(Get-ClusterResource -Name $fileServerRole).OwnerNode.Name
$session=New-PSSession -ComputerName $roleOwner
if($session){
Write-Host "Expanding $driveLetter for $fileServerRole currently owned by $roleOwner...";
Invoke-Command -Session $session -ScriptBlock{
param($driveLetter)
# Resize volume to its available maximum
Update-HostStorageCache
$max=(Get-PartitionSupportedSize -DriveLetter $driveLetter).SizeMax
Resize-Partition -DriveLetter $driveLetter -Size $max
} -Args $driveLetter
}
Remove-PSSession $session
Option 2: Expanding disk of a Windows Computer (Generic Approach)
# Expand Disk in Windows
# Change these values to match target machine
$computername="$env:computername"
$driveLetter='C'
$session=New-PSSession -ComputerName $computername
if($session){
Invoke-Command -Session $session -ScriptBlock{
param($driveLetter)
try{
Update-HostStorageCache
$max=(Get-PartitionSupportedSize -DriveLetter $driveLetter).SizeMax
write-host "$env:computername`: resizing volume $driveLetter to its available maximum..."
Resize-Partition -DriveLetter $driveLetter -Size $max -ea Stop
return $true
}catch{
write-warning $_
return $false
}
} -Args $driveLetter
}
Remove-PSSession $session
Categories: