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

Install Apps on Remote Computers via WinRM & Chocolatey

Version A: [string[]]$computers=@( 'SERVER01', 'SERVER02', 'SERVER03' ) [string]$chocoAppName='pgadmin4' [version]$minVersion='6.0' $results=[hashtable]@{} foreach ($computer in $computers){ $session=new-pssession…

PowerShell: List All IPs Used by Cluster

Snippet: # Obtain IPs of resources in clusterfunction getResourceIPs { $resourceIPs=Get-Cluster | Get-ClusterResource | ?{$_.ResourceType…

Use PowerShell to Grant SysAdmin Role to Certain Users

$principle=$env:USERDOMAIN+'\Domain Admins' $sqlServer=$env:computername function includeSqlTools{ $ErrorActionPreference='stop' try{ $trustedPsgallery=(Get-PSRepository PSGallery).InstallationPolicy -eq 'Trusted' if(!$trustedPsgallery){ Set-PSRepository -Name PSGallery…