Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cleanup-reboot gist 2
foreach ($workergroup in $workergroups){ # Iterate through workergroups
$checkworkergroup = @(get-xaworkergroup -ComputerName $DeliveryController | where-object {$_.WorkerGroupName -eq $workergroup})
if ($checkworkergroup.count -eq 0){
$finalout += "$workergroup is invalid. Confirm names in worker group list and try again.<br>"
write-verbose "$workergroup is invalid. Confirm names in worker group list and try again."
} else {
$workergroupservers = @(get-xaworkergroupserver -ComputerName $DeliveryController -workergroupname $workergroup | sort-object -property ServerName) # Create a query to pull the Worker Group membership
$finalout += "Checking servers in Worker Group: $WORKERGROUP<br>"
write-verbose "Checking servers in Worker Group: $WORKERGROUP"
foreach ($workergroupserver in $workergroupservers){ # Iterate through workergroup servers
$server = $workergroupserver.ServerName
if (($excludedservers -notcontains $server) -and ($OnlineServers -contains $server)) { # Check that server is not excluded and is online
if ("$server" -eq "$env:COMPUTERNAME") { # Bypass local server
} else {
$sessions = $xasessions | Where {$_.ServerName -eq $server} # Create a query against server passed through as first variable where protocol is Ica. Disregard listening sessions
if ($sessions.count -eq 0) { #Server has no users.
$wgServerLoad = Get-XAServerLoad -computername $DeliveryController -servername $server #Check server load
if ($wgServerLoad.Load -ge 3500) {
set-XAServerLogOnMode -ServerName $server -LogOnMode ProhibitNewLogOnsUntilRestart #Set ProhibitNewLogOnsUntilRestart
$finalout += "$server is online, but is hosting no users with load of $wgServerLoad. LogOnMode set to ProhibitNewLogOnsUntilRestart.<br>"
write-verbose "$server is online, but is hosting no users with load of $wgServerLoad. LogOnMode set to ProhibitNewLogOnsUntilRestart."
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment