Citrix : Slow Login, Profile Cleanup Script

Ran into a strange issue today with two Citrix servers, both suddenly started to exhibit extremely long logins of ~3 minutes – this initially meant that users could not access any published applications on the servers due to the default LogoffCheckerStartupDelayInSeconds timeout of 60 seconds. Sessions would start, hang at the “Welcome” stage of the Citrix application startup and then the session would terminate after 60 seconds.

We modified this registry key to 180 seconds and applications would then launch, workaround in-place, but what was really causing the issue?

After a LOT of troubleshooting it was discovered that there were 100+ profile folders on the servers. We scripted cleanup of these profiles using the script below, login times dropped to ~25 seconds.

You’ll need to ensure you modify the list of profiles you want to keep, as defined in the first line of the script – I’m not responsible for any data lost – you are! You should, no must, test this in a lab first…

The following script can be used, and scheduled, to cleanup stale profiles. 

$arrNames = "admin","All Users","Classic .NET AppPool","Ctx_StreamingSvc","Default",     "Default User","limssched","Public","Waters","sophosupd","SUSR_UDA","NetworkService","LocalService","systemprofile" $profiles = Get-WmiObject Win32_UserProfile  foreach ($profile in $profiles) {     $username = $profile.LocalPath.split('\\')[-1]     If ($arrNames -NotContains $username) {    write-host "Will delete profile for USER: $username, ***PATH:" $profile.localpath}     If ($arrNames -NotContains $username) {    $profile.delete } }