Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remotely expand all volumes on a server that have available space.
Function Invoke-RemoteVolumeExpand
{
Param
(
$Server
)
Function Invoke-VolumeExpand
{
$Include = "C|W|D|E|F"
$Partitions = Get-Partition | Where-Object {$_.DriveLetter -Match $Include}
Foreach ($Partition in $Partitions)
{
$Type = $Partition.Type
$Letter = $Partition.DriveLetter
If ($Type -eq "Basic")
{
$Size = $Partition | Get-PartitionSupportedSize
$MaxSize = $Size.sizeMax
$MinSize = $Size.sizeMin
If ($MaxSize -ne $MinSize)
{
Try
{
Write-Output "$Server Expanding $Letter to $MaxSize"
$Partition | Resize-Partition -size $MaxSize -ErrorAction SilentlyContinue
}
Catch
{
Write-Output "$Server No further expansion possible for $Letter"
}
}
}
}
}
Invoke-Command -ComputerName $Server -ScriptBlock ${Function:Invoke-VolumeExpand}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.