Skip to content

Instantly share code, notes, and snippets.

@AshFlaw
Created May 14, 2018 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshFlaw/9aa21eb9a110f1337dcb7f0277650054 to your computer and use it in GitHub Desktop.
Save AshFlaw/9aa21eb9a110f1337dcb7f0277650054 to your computer and use it in GitHub Desktop.
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