How to Build an Evict Script

How to Build an Evict Script

book

Article ID: CTX232985

calendar_today

Updated On:

Description

To demonstrate how to build an evict script from scratch using PoSH SDK in order to remove a Delivery Controller from the database.

Depending on your XenApp &XenDesktop version, the number of services might change, consequently, the number of tables and data wrote to the database. That's why it is important to build the evict script for each specific use case.


Instructions

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 Logging –DatabaseName “MyLoggingDB” –ScriptType Evict –SID “Controller to evict SID”
Get-MonitorDBSchema -DataStore Monitor -DatabaseName "MyMonitorDB” –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 “filepath\name” –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.

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.

Issue/Introduction

To explain how to build a evict script to remove a Delivery Controller from the database.

Additional Information

Citrix Developer Documentation - XenApp and XenDesktop SDK