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: Try Catch Technique to Obtain Error Type

# Test try{Read-SCVirtualMachine $vmName -EA Stop}catch{$errorMessage=$error[0].Exception.GetType().FullNamewrite-host $errorMessage} # Get error type Microsoft.VirtualManager.Utils.CarmineException # Retry catch…

PowerShell: Obtain Date Time Stamp And Convert to Pacific Standard Zone

# 1-liner date stamp $dateStamp=[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId( (Get-Date), 'Pacific Standard Time').tostring("MM-dd-yyyy-HHmm")+'_PST' #sample output #06-15-2020-1949_PST $timeZone='Pacific Standard Time'…

PowerShell: Detect Whether Computer is Connected To Domain

# The easy method $domainConnected=.{ try { [void]::([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()) return $true } catch{ return $false }…