How to Build an Evict Script

The script should be built from a working DDC.

Summary

Generating Evict Script:

  1. Obtain the SID of the failed DDC.
  2. Get the database schemas for the site version.
  3. Configure the right command parameters to obtain the script.
  4. 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:

Get-BrokerController

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.

User-added image

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:

Get-Command Get*DBSchema

For 7.16 it will return:

User-added image

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

  1. Open a PowerShell ISE and open the script view.
  2. Add Citrix SnapIns and paste all the “get” commands obtained earlier alongside the parameter string build in the step before.
  3. Define two variables, one for the database name and the other one for the non-working SID.
  4. 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:

User-added image

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.

Related:

  • No Related Posts

Leave a Reply