Posted On March 11, 2020

PowerShell: Expand Volume of Virtual FileServer Role

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Expand Volume of Virtual FileServer Role
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

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Administering Network Time Protocol Settings on Windows

Quick Script of Domain Joined Laptops and Desktops for Remote Users: # Set Domain Joined…

The Process of Adding a New Hyper-V Server Into a Cluster and the Associated Virtual Machine Manager (VMM)

These are the steps: Install WindowsWindows 2019 Data Center Edition is the standard as of…

PowerShell: List Biggest Files and Folders on a Volume

# listBigFilesAndFolders-v0.01.ps1 # Set variables $parentDirectory="C:\" $depth=4 $topX=10 $excludeDirectories="C:\Windows","C:\Program Files","C:\Program Files (x86)" $clusterSizeOfNetworkShare=8192 # Sanitize…