Author Posts

January 27, 2016 at 9:05 am

I'm very new to powershell and am writing a script to reboot our Citrix XenApp servers. I think I'm doing everything well, but am getting stuck in one part and can't really understand.

So the script will go and query a workergroup to get all the servers on the workergroup, it will then change the logon to Prohibit logons until a restart.
It then selects all the servers with a zero load and bulk reboot them.

I want to put a time-freeze so that it will run again in about 5 hours.
This time, I want to select all the servers from that same workergroup with -eq logon prohibited with a zero load. But upon sending the reboot command prior, the servers that have a load upon the first initial reboot, they change the logon state to "Allowlogon" without rebooting the server. HELP

I'm attaching my little script below.

Add-PSSnapin CITRIX*

#select servers
$InitialReboot = Get-XAWorkerGroupServer -computername name -WorkerGroupName reboot-every2days

#disable login
$InitialReboot | Set-XAServerLogOnMode -LogOnMode ProhibitNewLogOnsUntilRestart

#reboot servers with 0 load
$InitialReboot | Get-XAServerLoad -ComputerName name | where load -eq 0
Restart-Computer $InitialReboot.servername -ErrorAction SilentlyContinue

#second reboot – five hours later
$CycleReboot = Get-XAWorkerGroupServer -ComputerName name -WorkerGroupName reboot-every2days | get-xaserver | Where-Object {$_.logonmode -eq "prohibitlogons"}

When I check this variable, it is empty and when I check the server that had a load during the initial reboot, whkch should be logon -prohibited, it is acutally enabled. When I run line by line, when the Reboot Servers with 0 load runs, it actually doesn't reboot the server but changes the logon state to "Allow logon"

Why is this happening?

January 27, 2016 at 1:36 pm

Hi Jay Q,

I'm not a citrix chap, but these lines stand out to me :

$InitialReboot | Get-XAServerLoad -ComputerName name | where load -eq 0
Restart-Computer $InitialReboot.servername -ErrorAction SilentlyContinue

The first line won't do anything other than list to the screen servers which have a load of 0 because you're not doing anything involving variable assignment or passing the information along the pipeline.

The second line looks like it will restart all the servers in $initialreboot?

January 27, 2016 at 1:48 pm

I suspect that pipe after the $InitialReboot on the first line was supposed to the an equal sign (assignment operator) or some other variable was supposed to be assigned to be used in the second statement.