By design the maintenance of a PVS Server is pretty easy, in a load balanced environment with at least two PVS Servers you can just take one down and the connections of the target devices are moving to the other Server.
Unfortunately, there is sometimes a gap between theory and reality… We had sometime the issue that the sessions were not handed over to the second one.
I spoke with Sacha Thomet (@sacha81) and he told me about his “chicken-hearted” workaround … I should statically configure all vDisks on a server, balance the load, and transfer on this way the sessions.
Because I manage an environment with a large amount of vDisks, I won’t do that manually. For this reason, I wrote this Script/Cmdlets. Affinity and rebalancing is no considered.
Be aware! If you have a not working Load balancing, you have an issue in your configuration, and I advise you to fix that, otherwise you will get in trouble sooner or later…
Get-UDPvsDiskLoadblanceInfos
With this cmdlet the LoadBalancing information can be read from one, several or all vDisks.
Set-UDPvsDiskLoadblance
This cmdlet is used to configure the vDisks. It specifies the site and server to be used, for one or more sites.
Set-UDPvsDiskLoadblance -Clear
At the end, the settings have to be reset, which means all vDisks have to be load balanced again.
Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
<# .NOTES =========================================================================== Created on: 29.03.2018 Created by: s.beckmann@unico.ws E-Mail: s.beckmann@unico.ch Organization: Unico Data AG Filename: Manage_Loadbalancing_of_vDisks.ps1 =========================================================================== .DESCRIPTION Cmdlet to configure loadbalancing on vDisks .CALL BY Import as module and use the cmdlet. .VERSION HISTORY 1.0 29.03.2018 - Initial release #> Function Get-UDPvsDiskLoadblanceInfos { <# .SYNOPSIS Get PVS vDisk information. .DESCRIPTION Get informations about the loadbalancing settings on vDisks. .PARAMETER DiskName The name of one or many vDisk, or wildecard .EXAMPLE Get-UDPvsDiskLoadblanceInfos -DiskName 'Win10' Get disk info about loadbalancing from vDsik Win10. .EXAMPLE Get-UDPvsDiskLoadblanceInfos -DiskName 'Win10','Win2012' Get disk info about loadbalancing from vDsik Win10 and Win2012. .EXAMPLE Get-UDPvsDiskLoadblanceInfos -DiskName '*' Get disk info about loadbalancing from all vDsiks. .EXAMPLE Get-UDPvsDiskLoadblanceInfos Get disk info about loadbalancing from all vDsiks. #> [CmdletBinding()] Param ( [Parameter( Mandatory = $False, Position = 0, ValueFromPipeline = $True )] [System.String[]] $DiskName = '*' ) foreach($Disk in $DiskName){ $Disks = Get-PvsDiskLocator -Fields Name,SiteName,ServerName | Where-Object {$_.Name -like $Disk} ForEach ($D in $Disks){ $Object = New-Object -TypeName psobject -Property @{ DiskName = $D.Name SiteName = $D.SiteName Servername = $D.ServerName } Write-Output $Object } } } Function Set-UDPvsDiskLoadblance { <# .SYNOPSIS Set PVS vDisk loadbalancing configuration. .DESCRIPTION Set loadbalancing configuration for one, many or all vDsiks. It's possible to set PVS Server per site and clear the static configuration. After loadbalancing is configured, the rebalancing will be started. .PARAMETER DiskName The name of one or manny vDisk, or wildecard .PARAMETER Server A hash table with Site and PVS Server .PARAMETER Clear To clear static loadbalancing configuration .EXAMPLE Set-UDPvsDiskLoadblance -DiskName 'Win10' -Server @{'Site1'='pvsserver01';'Site2'='pvsserver02'} Set the loadbalancing options for vDisk Win10, in Site1 to pvsserver01 and in Site2 to pvsserver02. Site1 has also pvsserver03 and Site2 pvsserver2 as PVS Site Server. .EXAMPLE Set-UDPvsDiskLoadblance -DiskName 'Win10','Win2012' -Server @{'Site1'='pvsserver01';'Site2'='pvsserver02'} Set the loadbalancing options for vDisk Win10 and Win2012, in Site1 to pvsserver01 and in Site2 to pvsserver02. Site1 has also pvsserver03 and Site2 pvsserver2 as PVS Site Server. .EXAMPLE Set-UDPvsDiskLoadblance -DiskName '*' -Server @{'Site1'='pvsserver01';'Site2'='pvsserver02'} Set the loadbalancing options for all vDisks, in Site1 to pvsserver01 and in Site2 to pvsserver02. Site1 has also pvsserver03 and Site2 pvsserver2 as PVS Site Server. .EXAMPLE Set-UDPvsDiskLoadblance -Server @{'Site1'='pvsserver01';'Site2'='pvsserver02'} Set the loadbalancing options for all vDisks, in Site1 to pvsserver01 and in Site2 to pvsserver02. Site1 has also pvsserver03 and Site2 pvsserver2 as PVS Site Server. .EXAMPLE Set-UDPvsDiskLoadblance -DiskName 'Win10' -Clear Set the loadbalancing options for vDisk Win10 to loadbalance. .EXAMPLE Set-UDPvsDiskLoadblance -DiskName 'Win10','Win2012' -Clear Set the loadbalancing options for vDisk Win10 and Win2012 to loadbalance. .EXAMPLE Set-UDPvsDiskLoadblance -DiskName '*' -Clear Set the loadbalancing options for all vDisks to loadbalance. .EXAMPLE Set-UDPvsDiskLoadblance -Clear Set the loadbalancing options for all vDisks to loadbalance. #> [CmdletBinding()] Param ( [Parameter( Mandatory = $False, Position = 0, ValueFromPipeline = $True )] [System.String[]] $DiskName = '*', [Parameter( Mandatory = $False, Position = 1, ValueFromPipeline = $True )] [System.Collections.Hashtable] $Server, [Parameter( Mandatory = $False, Position = 2, ValueFromPipeline = $True )] [switch] $Clear = $False ) foreach($Disk in $DiskName){ $Disks = Get-PvsDiskLocator -Fields Name,SiteName,ServerName | Where-Object {$_.Name -like $Disk} ForEach ($D in $Disks){ $Object = New-Object -TypeName psobject -Property @{ DiskName = $D.Name SiteName = $D.SiteName Servername = $D.ServerName } If ($Clear){ $D.ServerName = $Null } Else { $D.ServerName = $Server.($D.SiteName) } Set-PvsDiskLocator $D If (!$Clear){ $ServerToClearDevice = Get-PvsServer -Fields Name,SiteName | Where-Object {($_.SiteName -eq $D.SiteName) -and ($_.Name -ne $Server.($D.SiteName))} Invoke-PvsRebalanceDevices -ServerName $ServerToClearDevice.Name | Out-Null } $tmpD = Get-PvsDiskLocator -Fields Name,SiteName,ServerName | Where-Object {($_.Name -eq $D.Name) -and ($_.SiteName -eq $D.SiteName)} $Object | Add-Member -MemberType NoteProperty -Name 'NewServername' -Value $tmpD.ServerName Write-Output $Object } } If ($Clear){ $Servers = Get-UDPvsDeviceLoadblanceInfos | Sort-Object SiteName $Sites = $Servers.SiteName | Select -Unique ForEach ($Site in $Sites){ $Compare = $Servers | Where-Object {$_.SiteName -eq $Site} $max = ($Compare | measure-object -Property DeviceCount -maximum).maximum $ServerToRebalance = $Compare | ? { $_.DeviceCount -eq $max} ForEach ($S in $ServerToRebalance){ Invoke-PvsRebalanceDevices -ServerName $S.Name | Out-Null } } } } Function Get-UDPvsDeviceLoadblanceInfos { <# .SYNOPSIS Get information about the load from PVS Servers. .DESCRIPTION Get information about the device load from all PVS Server in any Site in the same Farm. .EXAMPLE Get-UDPvsDeviceLoadblanceInfos Get Informations about the loadbalancing. #> $Info = Get-PvsServerInfo |Select Name,SiteName,DeviceCount Write-Output $Info } if ((Get-PSSnapin "Citrix.PVS.SnapIn" -EA silentlycontinue) -eq $null) { try { Add-PSSnapin Citrix.PVS.SnapIn -ErrorAction Stop } catch { write-error "Error loading Citrix.PVS.SnapIn PowerShell snapin"; Return } } cls |