Created
May 14, 2018 13:38
-
-
Save AshFlaw/9aa21eb9a110f1337dcb7f0277650054 to your computer and use it in GitHub Desktop.
Remotely expand all volumes on a server that have available space.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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