The script should be built from a working DDC.
Generating Evict Script:
- Obtain the SID of the failed DDC.
- Get the database schemas for the site version.
- Configure the right command parameters to obtain the script.
- Build the PoSH script to generate the SQL script.
Launch a PowerShell prompt and add Citrix modules (asnp Citrix*).
1. Obtain the SID of the failed DDC
To obtain the failed DDC SID on the database, run the following command:
It should return the list of controllers for the site and the state of each one of them.
It’s important to run this command to obtain the controller SID because we need the SID registered on the db, not the one on AD since it might be slightly different if the account has been removed and recreated, or changed the SID in any other way.
Notice that the failed Controller State is “OFF”.
2. Get the database schemas for the site version
In order to know which database schemas do you need to clean on the database, run the following command:
For 7.16 it will return:
Open a PowerShell ISE as an administrator and paste all the commands.
3. Configuring the right command parameters to obtain the script
For each DBSchema command, you can configure the same parameters, meaning that the syntax will work for all of them.
According to the latest PoSH SDK documentation available, the minimum required parameters to build an Evict script are:
- –DatabaseName: Meaning the site database
- –ScriptType: We will use “Evict”, however, we can generate Login or full database scripts.
- –SID: SID stored on the database for the controller that we want to evict.
So the parameters for each service DBSchema should look like:
Get-LogDBSchema –DatabaseName “MySiteDB” –ScriptType Evict –SID “Controller to evict SID”
Also for Monitor and Logging schema, you can remove the data on the Site DataStore by using the following commands:
Get-LogDBSchema -DataStore Site –DatabaseName “MySiteDB” –ScriptType Evict –SID “Controller to evict SID”
Get-MonitorDBSchema -DataStore Site -DatabaseName “MySiteDB” –ScriptType Evict –SID “Controller to evict SID”
4. Building the PoSH script to generate the SQL script
- Open a PowerShell ISE and open the script view.
- Add Citrix SnapIns and paste all the “get” commands obtained earlier alongside the parameter string build in the step before.
- Define two variables, one for the database name and the other one for the non-working SID.
- We will also need to add a function to write the content to a file. There are several ways to do it, but I’ll be using Out-File “filepathname” –Append
So the script should look like:
Once you run it, go to the path and you will find the Evict.sql file generated which is a SQL script that can be run either on the SQLCMD or the Management Studio in SQLCMD mode.