Automatic reboot and correct logoff for citrix

In addition to the Remote Desktop reboot i’ve created one for citrix as well.

This customer had two catalogs, and thay didn’t want the second machine catalog to be rebooted each day. Replace the $XACatalogName with you own.

Add-PSSnapin citrix.*

$XACatalogName = "XenApp Production Servers"

$MessageSubject = "Reboot Schedule"
$MessageBody = "You have entered the daily reboot schedule. Please save your work. You will be logged off automatically within 5 minutes"

$SessionHosts = Get-BrokerMachine -CatalogName $XACatalogName  | select DNSNAME, MachineName

#Send Message to Users that they will be logged out

foreach ($Hosts in $SessionHosts ) {

$SessionUsers = Get-BrokerSession  -MachineName $Hosts.MachineName

Foreach ($SessionUser in $SessionUsers) {

Send-BrokerSessionMessage -InputObject $SessionUser.Uid -MessageStyle "Information"  -Title $MessageSubject -Text $MessageBody

}

}

#Timedelay before logging user off
Start-Sleep -s 300

#Log Users off and reboot

foreach ($Hosts in $SessionHosts ) {

#echo $Hosts.SessionHost #debugUse

$SessionUsers = Get-BrokerSession  -MachineName $Hosts.MachineName

Foreach ($SessionUser in $SessionUsers) {
Stop-BrokerSession -InputObject $SessionUser.Uid
}

Restart-Computer -Force -ComputerName $SessionHosts.DNSName
}

Was this site helpful? 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Loading...