Close-up of Vikash's eyes behind his favourite dark-rimmed glasses About Roy

How to remove XenDesktop DDC5 gracefully from the XD5 farm

In my previous blog I mention hard way to remove stale DDC from XD database.

Launch the Desktop Studio and highlight controllers as shown below. Select the controller you want to remove and choose "Remove Controller"

How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 1

This will prompt for action to update Database . Choose "NO " here How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 2

This will prompt for generating SQL script which needs to be run on SQL server database

How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 3

Script looks like this . Copy this script

How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 4

And then choose DDC database on SQL manager . Right click and select new script . Paste  it from previous step and run "Execute"

How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 5

Once the script is ran then it will give following message

How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 6

Once Desktop Studio is update , controller will be removed

How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 7

Run powershell command Get-BrokerController and confirm that other controller is out completely.

How to remove XenDesktop DDC5 gracefully from the XD5 farm — screenshot 8

How to remove stale DDC from XenDesktop 5 Farm

Stale DDC inside XenDesk 5 Farm may get created because of various reason and this does not get removed unless database is cleaned.

1. If you run Get-brokercontroller from PS console of Desktop Studio then you see the stale entry. Below two stale entry for SID

S-1-5-21-1757981266-413027322-725345543-64627 and  other one ending with 64712How to remove stale DDC from XenDesktop 5 Farm — screenshot 1 

2. Same thing will be shown via Desktop Studio

 How to remove stale DDC from XenDesktop 5 Farm — screenshot 2

3. Following script needs to be run in same order from desktop studio PS console with XD database name

Get-ConfigDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid > EvictDDC.sql  (Here we are creating EvictDDC.sql)
Get-AcctDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid >> EvictDDC.sql(Here we are appending to  EvictDDC.sql)
Get-HypDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid >> EvictDDC.sql
Get-ProvDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid >> EvictDDC.sql
Get-PvsVmDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid >> EvictDDC.sql
Get-BrokerDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid >> EvictDDC.sql

4. This is how Script needs to be run in following order . First SID variable needs to be set and then rest of the commands need to be run. Here we are creating EvictDDC.sql file which is nothing but a stored procedure

How to remove stale DDC from XenDesktop 5 Farm — screenshot 3

5.  This file can be found under following

How to remove stale DDC from XenDesktop 5 Farm — screenshot 4

6. Now when we open this file with notepad  following entry can be found.

How to remove stale DDC from XenDesktop 5 Farm — screenshot 5 

7.   Open SQL server management studio and select the database and then open new script. Select the content from EvictDDC.sql  and paste as shown. Execute as shown below

How to remove stale DDC from XenDesktop 5 Farm — screenshot 6

8.   Last command Get-BrokerDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid >> EvictDDC.sql  need to run as follows.

How to remove stale DDC from XenDesktop 5 Farm — screenshot 7

9.  Sometime Get-BrokerDBSchema -DatabaseName <XD database name> -ScriptType Evict -SID $sid >> EvictDDC.sql will fail with following message. Create new store procedure using working XD SID and then replace host name and SID with non working SID.

How to remove stale DDC from XenDesktop 5 Farm — screenshot 8

10.  Once all the above store procedure ran it will remove the stale entry from DDC

How to remove stale DDC from XenDesktop 5 Farm — screenshot 9

Even Desktop Studio will update the entry

 How to remove stale DDC from XenDesktop 5 Farm — screenshot 10