Pages

Sunday, March 3, 2013

Manually removing orphaned Citrix XenDesktop 5.6 DDC (Desktop Delivery Controller)

Problem

You noticed that you have an orphaned Citrix XenDesktop 5.6 DDC (Desktop Delivery Controller) that no longer exists in your environment but is shown in Desktop Studio with a red X:

image

Since the desktop controller no longer exists, you are unable to perform an uninstall to remove it from the environment.

Solution

While I didn’t figure this one out myself as it had to do with cleaning up the SQL database hosting the Citrix XenDesktop configuration information, I thought it would be a good idea to share the solution that an escalated Citrix engineer provided because I have a feeling I’ll come across this issue again.  Before I begin, it’s important to note that you should back up your database before you execute these scripts as there may be situations that these scripts aren’t applicable to.

The following is the PowerShell cmdlet that the Citrix engineer provided me that would create the SQL script to remove the orphaned DDC:

$db = "CitrixXenDesktopDB"
$sid = "DCC-SID"   
New-Item -ItemType file "$PWD\evict_$sid.txt" -Force
Add-Content "$PWD\evict_$sid.txt" (Get-ConfigDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-AcctDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-HypDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-ProvDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-PvsVmDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-BrokerDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Invoke-Item "$PWD\evict_$sid.txt"

Note that the items highlighted in red are to be changed to the appropriate values as it pertains to your environment.  The CitrixXenDesktopDB will be the name of your database as shown on the SQL server and the DCC-SID is retrieved with the Get-BrokerController cmdlet as shown here:

image

**Note that the third DDC listed from the PowerShell cmdlet is the orphaned DDC.

With the information provided above, the cmdlet I executed is as follows:

$db = "XenDesktopFarm"
$sid = "S-1-5-21-1638170406-968170735-313593124-13806" 
New-Item -ItemType file "$PWD\evict_$sid.txt" -Force
Add-Content "$PWD\evict_$sid.txt" (Get-ConfigDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-AcctDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-HypDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-ProvDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-PvsVmDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Add-Content "$PWD\evict_$sid.txt" (Get-BrokerDBSchema -DatabaseName $db -ScriptType Evict -SID $sid)
Invoke-Item "$PWD\evict_$sid.txt"

The following screenshot shows what executing the cmdlet above should look like:

image

Once cmdlet above successfully executes, you should see Notepad automatically open with the following content:

image

Copy the contents in the Notepad and paste it into a query within in Microsoft SQL Server Management Studio:

image

With the script pasted, proceed to execute it and ensure that no errors are thrown.  What I noticed in my situation when I executed this script was that I received the following error:

Msg 102, Level 15, State 1, Line 26

Incorrect syntax near ‘:’.

Database user for login [domain\orphanedDDCName$] deleted

image

What’s strange was that I navigated to the line to look for syntax errors but couldn’t find it so just to be sure the whole script executed, I began to execute the script in chunks by lighting the sections individually:

image 

image

While a bit cumbersome, this allowed me to confirm that each block executed successfully.  Once I finished executing all of the blocks, I went into the Desktop Studio management console to confirm that the DDC has been removed:

image

No comments: