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: Set User Option Change Password At Next Logon

$ou="OU=Users,DC=corp,DC=hooli,DC=com" $usersInOu=Get-ADUser -Filter * -SearchBase $ou $usersInOu|Set-ADUser -CannotChangePassword:$false -ChangePasswordAtLogon:$false

Basic CSS: Use Clockwise Notation to Specify the Margin of an Element

<style>.injected-text {margin-bottom: -25px;text-align: center;}.box {border-style: solid;border-color: black;border-width: 5px;text-align: center;}.yellow-box {background-color: yellow;padding: 20px 40px 20px 40px;}.red-box…

PowerShell: Add Office365 Records on DNS Servers

Make Changes to Internal DNS A. Delete Old CNAMES and MX Records Sample commands from…