Upgrading XenDesktop, you probably will fail. But you will find your way out of the problem.

Last few times I have done XenDesktop 7.x upgrade in production, it fails on upgrading the database automatically. And will tell you to do a manual upgrade of your databases. Only comfort is that it seems to be something others experience commonly also, but it is as expected. Weird thing is that I have never had this kind of problem in a lab environment.

But “when” you do run into problems like this, you will (at least I am naive enough to do) probably think that doing as Citrix says and run the disable script on first controller then run the sql scripts will do the trick. Think again, always room for new errors with Citrix upgrades.

Yesterday we ended up with messages like this when running the sql script for site database.

Msg 50000, Level 18, State 1, Procedure StartUpdate, Line 63
StartUpdate: Update requires all services to be stopped
What we discovered is that the process given by John Powell here http://discussions.citrix.com/topic/350557-xd75-upgrade-disableservicesps1-hangs/ almost nails it.
So our process ended up like this:
  1. Snapshot XenDesktop controllers
  2. Backup SQL databases
  3. Run Upgrade from XenDesktop ISO
  4. Start studio and run the automatic upgrade (wich fails)
  5. Copy the powershell scripts output from manual upgrade to all controllers.
  6. Edit powershell scripts to match adminserver to hostname of all servers
  7. Run the DisableServices script as administrator on all controllers (This is supposed to clear out all active connections to the database. Make sure no errors occur).
  8. Copy the sql files given from manual upgrade to sql server.
  9. Check that there are no active connections to the databases you want to upgrade (use the command sp_who in SQL Studio)
  10. If there still is active connections from a controller, reboot that controller to reset connections. Check again for active connections.
  11. Run the sql scripts, we followed Johns sequence, Site, Monitor, Logging. (command in cmd

    sqlcmd -S SERVERNAME -i c:\UpgradeLoggingDatabase.sql -o output.txt) 

  12. Run the EnableServices script as administrator on first Controller, all services should be re-established without errors (if not you will have to troubleshoot the eventual error)
  13. Open Studio on the first Controller, Continue with the automatic upgrade (should be your only option)
  14. Verify upgrade ok
  15. Upgrade next controllers using XenDesktop ISO
  16. Run EnableServices script as administrator on the controllers before moving to the next.
  17. Open Studio and re-register controller, should be an option in main window of Studio.
  18. Verify upgrade ok
  19. Run step 15-18 until you have upgraded all controllers.
  20. Remember to clean up snapshots and backup when you are comfortable with upgrade is a success.

My choice in the future definitely will be to run Manual upgrade.

I really wish Citrix could put some real effort into improving upgrades on especially XenDesktop and Storefront, it is costly to clean up their mess every time.

XenDesktop 7 custom icon for published application

This process will add a new icon to your XenDesktop database that you can use with your applications.

Convert your logo file to icon here http://converticon.com/

asnp citrix*

Get-CtxIcon -FileName C:\Temp\youriconfile.ico |New-BrokerIcon
# Note the Uid

Get-BrokerApplication -name "yourapplication" | Set-BrokerApplication -IconUid Uid

Netscaler VPX on ESX looses network connectivity

Today we ran into an issue with Netscaler VPX installed on ESX. It lost network connectivity, and after a reboot it would have random packet loss for a while. And in console we could see it had troubles keeping the interface up.

Turns out there was an ongoing patching of ESX, and the result was troubles with Netscaler. Google brought https://communities.vmware.com/thread/492945 to the table, which seems to be a working work around.


Powershell check service status and eventually start if stopped

I mostly use this script for checking all XenDesktop app hosts if print spooler is running, and if its not it will try to start it.

First it finds all registered hosts from XenDesktops, and then query the spooler service and eventually try to start it if it is stopped.

To check/start other services, just enter servicename in $service variable.

$xendesktopController = "deliverycontroller.domain.local"
$onlineHosts = @()
$service = "spooler"
## This function gets all online hosts with status as registered in XenDesktop. This way we dont have to wait for hosts thats not accepting users anyways.
## Result is output to a CSV on c:\scripts\
function getOnlineHosts {
Write-host -ForegroundColor Yellow -BackgroundColor Black "*********************************************"
Write-Host -ForegroundColor Yellow -BackgroundColor Black "** Getting online hosts.....be patient.... **"
Write-Host -ForegroundColor Yellow -BackgroundColor Black "*********************************************"
$psremote = New-PSSession -ComputerName $xendesktopController
Invoke-Command -Session $psremote { asnp citrix* }
Invoke-Command -Session $psremote -scriptblock { Get-BrokerMachine -Filter { RegistrationState -eq 'Registered' } | Select-Object dnsName} | Export-Csv c:\scripts\onlinehosts.csv


## Reads CSV and checks spooler status on each host, if not running, service is started.
function checkAndStartSpooler
$onlineHosts = Import-Csv c:\scripts\onlinehosts.csv
foreach ($h in $onlineHosts)
$pshost = $h.DNSName
Write-Host -BackgroundColor Black "Checking spooler status on: " $h.DNSName
Invoke-Command -ComputerName $pshost {
$serviceStatus = Get-Service -Name Spooler
if ($serviceStatus.Status -ne "Running")
Start-Service -Name Spooler
Write-host -ForegroundColor Red -BackgroundColor Black "Started Spooler on: " $env:COMPUTERNAME
Write-host -ForegroundColor Green -BackgroundColor Black "Spooler checked out fine on: " $env:COMPUTERNAME

## Calling functions.


XenDesktop monitor registration state

These days, we have had a lot of trouble with a XenDesktop 7.1 farm that have VM’s unregister with controller and in many times leaving the VM “half dead”. So i spent a few days with refreshing Studio to watch for VM’s going in to unregistered state. Today I spent a few minutes and created a script that does the same thing in PoSh. Refreshing every 30 seconds.

This probably could be better written on a one-liner, but I really dont like one-liners they are messy :)

asnp citrix*
$i = 1
while ($i -eq 1) {
Get-BrokerDesktop|select MachineName,RegistrationState|sort RegistrationState|ft
Start-Sleep -Seconds 30

Remote initialize and format newly added harddrive

Handy little script that initializes your newly added harddisk and then format it.

function initalizeDisk ($dnsname)
$psremote = New-PSSession $dnsname
Invoke-Command -Session $psremote { Get-Disk |

Where partitionstyle -eq 'raw' |

Initialize-Disk -PartitionStyle MBR -PassThru |

New-Partition -AssignDriveLetter -UseMaximumSize |

Format-Volume -FileSystem NTFS -NewFileSystemLabel "WriteCache" -Confirm:$false



Print test page to all your printers from Powershell

I recently had a task, requiring me to print a testpage to all printer queues on a printserver. With somewhere around 150 queues, this is certainly something i won’t do manually. So i created a little snippet to perform my task.

I know this could be done in one line, but I really dislike that way of writing code.

$printers = Get-Printer | select Name

foreach ($printer in $printers) {

Write-Host "Spooling Test Page to Printer: " $printer.name

rundll32 printui.dll,PrintUIEntry /k /n $printer.name


Duplicate all applications in XenDesktop 7 to new delivery group

This little powershell script will get all current applications from your current delivery group, and duplicate it to a new. 

asnp citrix*

$apps = Get-BrokerApplication | select BrowserName

foreach ($app in $apps)
$in = Get-BrokerApplication -BrowserName $app.BrowserName
Write-Host “Duplicating app to new deliverygroup: ” $in.BrowserName
#$in | Add-BrokerApplication -DesktopGroup “Server 2012v2”