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

WordPress Custom CSS for Tables

WordPress themes can be customized, and one of the common practice is to add CSS…

PowerShell: Purge OneDrive

# purgeOneDrive_v0.0.1.ps1function purgeOneDrive{ write-host "Halting OneDrive and explorer processes..." taskkill.exe /F /IM "OneDrive.exe" taskkill.exe /F…

PowerShell: Gather All Guess VM of All Hyper-V Clusters in the Domain

# getAllVms.ps1 $clusterName='*' function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 = "https://download.microsoft.com/download/1/D/8/1D8B5022-5477-4B9A-8104-6A71FF9D98AB/WindowsTH-RSAT_WS_1709-x64.msu"…