Sometimes Citrix application servers that are automatically rebooted through Citrix Server Policy can become hung during the process and marked with logins disabled.   When this happens the users were weaned from the server, but the server didn’t actually reboot.  As an administrator you will likely want to get this server back into production ASAP.  The following script will look through your XenApp Farm Servers for servers with disabled logins and when configured appropriately will email your Citrix administrators the servers with disabled logins. This applies to Citrix XenApp6.

[wp_ad_camp_1]

This should be run after your reboot scripts are expected to be complete and can be automated via scheduled task.  Let’s get started!

1)      Create an account that can be used to run this as a scheduled task.  This account must have access to your Citrix XenApp Farm.

2)      Create a folder called DLogins on the XenApp server this script will run from

3)      Modify the #Email the Report to your Citrix Administrators section of the script to reflect the settings and email addresses for your environment.  The most important variables to change are shown here.

4)      Save the following code as a .ps1 file to any directory on the Citrix XenApp server you are running the script from.

#Load the Citrix XenApp Powershell Commands

Add-PSSnapin “Citrix.XenApp.Commands” -ErrorAction SilentlyContinue

#Create html file and get XenApp Servers sorted alphabetically
[string]$path = “C:\DLogins\logonsd.html”
$servers = Get-XAServer | where {$_.LogonsEnabled -eq $false} | select ServerName, LogonsEnabled | Sort-object -Property LogonsEnabled | ConvertTo-HTML -As Table -body ”
<h1>Citrix Servers with Disabled Logins</h1>
The following report was run on $(get-date)” >> $path

#Email the Report to your Citrix Administrators
$emailserver = “smtp.domain.com”
$msgfrom = “[email protected]
$msgto = “[email protected]
$msgsubject = “Citrix Servers with Disabled Logins”
$body = get-content “C:\DLogins\logonsd.html”
$message = New-Object System.Net.Mail.MailMessage $msgfrom, $msgto
$message.subject = $msgsubject
$message.IsBodyHTML = $true
$message.Body = $body
$smtp = New-Object Net.Mail.SmtpClient($emailserver)
$smtp.Send($message)

#Delete the html file
Remove-Item C:\DLogins\logonsd.html -recurse

Create a scheduled Task to execute the newly created .ps1 file

  • Request or create a service account to run the scheduled task.  This account will need administrator access to Citrix and should not be used for anything else.
  • Sign into a server that has Citrix XenApp and the Citrix XenApp SDK installed
  • Open Task Scheduler through the server Control Panel.
  • In the Task Scheduler console expand the tree on the left hand side until you see Microsoft.  From there, right-click on Microsoft and choose “Create Task”.

task1

  • Give your scheduled task a name and then check the radio button marked to “Run whether user is logged on or not”.

task2

  • On the Triggers Tab, in the bottom left corner click the “New” button and create an appropriate schedule for your task.

Note:  This frequency should be determined by how often you expect your Citrix servers  reboot and should be run after reboots are expected to be completed.

task3

  • Click on the Actions Tab and then in the bottom left hand corner click the “New” button.

task4

  • Fill in the Program/Script and Add Arguments Fields.  See below for the syntax for each field and adjust accordingly for your environment
  • Program/Script:  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Add Arguments (Optional): -ExecutionPolicy Bypass -File “C:\directorynamechosenabove\filenamechosenabove.ps1”
    • Skip the conditions Tab.
    • Click on the settings tab and adjust to your preferences; however, please note that the default settings are typically ok.

task5

  • Click Ok.
  • You will be prompted to enter the password for the account used for the scheduled task.

Upon completion of this series of steps this script will run on the scheduled interval of your choice and receive a report that will let you know when your Citrix Servers are stuck with their logins disabled and have not rebooted.

error

Enjoy this blog? Please spread the word :)