NetScaler Scripting

Last Modified: Nov 21, 2019 @ 9:18 am


💡 = Recently Updated


  • 2019 Mar 11 – Script to Extract Configuration – rewrote the section in instructional format
  • 2018 Dec 2 – Configuration Extractor – added a nFactor visualizer
  • 2018 Nov 17 – Configuration Extractor – Out-GridView (GUI) for vServer selection
  • 2018 Sep 19 – Configuration Extractor – several fixes
  • 2018 July 4 – Configuration Extractor
    • Added “*” to select all vServers
    • Updated for 12.1 (SSL Log Profile, IP Set, Analytics Profile)
    • Extract local LB VIPs from Session Action URLs (e.g. StoreFront URL to local LB VIP)
    • Extract DNS vServers from “set vpn parameter” and Session Actions
  • 2018 Jan 4 – Configuration Extractor, Sirius’ Mark Scott added code to browse to open and save files. Added kcdaccounts to extraction.
  • 2018 Jan 3 – new Powershell-based NetScaler Configuration Extractor script

NetScaler ADC Configuration Extractor

NetScaler ADC Configuration Extractor extracts every NetScaler ADC CLI command needed to rebuild one or more Virtual Servers. Here’s how to use the script:

  1. The extraction script loads a NetScaler ADC Configuration file and parses it. To get a NetScaler ADC Configuration file:
    1. On your NetScaler ADC, go to System > Diagnostics > Running Configuration and then click the link on bottom to save text to a file.

  2. To download the extraction script, point your browser to, right-click the Raw button, and Save link as.
  3. Run the extraction script in PowerShell. One option is to right-click the script file and click Run with PowerShell. (note: the script doesn’t seem to work on Windows 7)
  4. Browse for the Running Configuration file that you saved from an appliance.
  5. The script will prompt you to select one or more Virtual Servers.
  6. The script then enumerates all objects linked to the chosen Virtual Servers (e.g. Responder Policies) and provides their configuration too.
  7. The script also outputs global settings that might affect the operation of the chosen Virtual Servers.
  8. The CLI output is listed in proper order. For example, create monitors before binding them to Service Groups.
  9. If the config includes an “authentication vserver”, then a nFactor Visualizer will be shown.
  10. The extracted Virtual Server CLI configuration can be used for documentation
  11. Or you can apply the outputted configuration to a different NetScaler ADC appliance:
    1. To import this output to a different NetScaler ADC, first change the IP addresses of the outputted Virtual Servers so there won’t be any IP Conflict after you import.
    2. SSH (Putty) to the other NetScaler ADC.
    3. Then simply copy the outputted lines and paste them into the SSH prompt.
    4. Alternatively, for longer output file, you can upload the output file to the other NetScaler ADC (e.g. upload to /tmp directory), and then run batch -fileName on the new NetScaler ADC while specifying the uploaded filename (e.g. /tmp/nsconfig.conf).
      • Note: the batch command requires that the input file name be in lower case only and without any spaces in the file name.

I originally attempted a dynamic extraction using complicated regular expressions, but there wasn’t enough control over the extraction and output process. The new PowerShell script explicitly enumerates specific objects, thus providing complete control over the output. For example, before binding a cipher group to a Virtual Server, the current ciphers must first be removed.

The script uses several techniques to avoid false positive matches, primarily substring matches.

Let me know what bugs you encounter.

Configure NetScaler ADC from PowerShell

You can use any scripting language that supports REST calls. This section is based on PowerShell 3 and its Invoke-RestMethod cmdlet.

Brandon Olin published a PowerShell module for NetScaler at Github.  💡

CTP Esther Barthel maintains a PowerShell module for NetScaler at See Citrix Synergy TV – SYN325 – Automating NetScaler: talking NITRO with PowerShell for an overview.

The below contains PowerShell functions that use REST calls to configure a NetScaler appliance. It only takes a few seconds to wipe a NetScaler and configure it with almost everything detailed on this site. A glaring omission is file operations including licenses, certificate files, and customized monitor scripts and the PowerShell script assumes these files are already present on the appliance.

Most of the functions should work on 10.5 and 11.0 with a few obvious exceptions like RDP Proxy. Here are some other differences between 10.5 and 11.0:

  • PUT operations in NetScaler 11 do not need an entity name in the URL; however 10.5 does require entity names in every PUT URL.
  • https URL for REST calls works without issue in NetScaler 11, but NetScaler 10.5 had inconsistent errors. http works without issue in NetScaler 10.5.

Nitro REST API Documentation

NetScaler Nitro REST API documentation can be found on any NetScaler by clicking the Downloads tab. The documentation is updated whenever you upgrade your firmware.

Look for the Nitro API Documentation.

Extract the files, and then launch index.html.

Start by reading the Getting Started Guide, and then expand the Configuration node to see detailed documentation for every REST call.

The Nitro API is also documented at REST Web Services at Citrix Docs.

25 thoughts on “NetScaler Scripting”

  1. I am looking for scripts which can configure basic SSL based Storefront, Director, WEM loadbalanced VIPs and bind Gateway on the latest NSVPX-ESX-13.0-47.24_nc_64. I have a lab environment and would really like to automate the basic Gateway configurations – but I am not a scripter. I tried to get my head around this NITRO stuff/Powershell – i find it very hard to grasp it.

    Searched and even tested Esther Barthel’s scripts but they seem to have errors. Somethings work and something error out.

    Please help me out 🙂


  2. Hi Carl

    we have some method to create a task scheldule in Netscaler to disable and enable some members group from one service group via scripting.


    1. NetScaler has a BSD shell with cron. Or you can use a scheduler on any remote machine and have it run scripts that do Nitro API to the NetScaler.

  3. Hi Carl. Any idea if NITRO can be used to send arbitrary shell commands to the NetScaler? I’m using Ether Barthel’s PS module and the built-in cmdlets work great, but I don’t see any way to send, e.g. “shell; df -h /var” and get that back.

      1. Thanks, Carl. While disk stats will prove helpful, unfortunately, for my particular requirement I was forced to go a different route. Since I needed to run the following command “find /var/ns_system_backup/ -maxdepth 1 -name backup* -mtime +14 -exec rm -rf {} \;”, I wrote a PowerShell script that calls “plink.exe” from the Putty distribution, and runs it against the list of NetScalers. Thanks for the help!

  4. Hi Carl,

    This is really cool stuff.
    I was trying to get ssl certificates with bindings plus I want to add one more column there for Certificate expiration dates.

    Any suggestion on this.

  5. Carl- I am looking to pull a list of ALL SSL Certificates installed on the Netscaler and each resource – each SSL cert is bound to.
    I have inherited an SSL MESS and the GUI is too slow and painful to go through the 400 + certs.
    I was hoping a PS script would work but I do not know how to start this.


      1. When I did the JSON – I received this:
        {“errorcode”:-1,”message”:”Invalid query parameters”,”severity”:”ERROR”}

        1. What build of NetScaler? Download the Nitro documentation from your Downloads page and check the syntax.

          I had to add ?bulkbindings=yes to get it to work.

    1. I got something for people in Leo’s situation. There is Powershell Nitro Library from Citrix I have added some scripts in my branch to collect inventory on VServers and associated certs (might get merged into the original repo maintained by CognitionIT as well)

      I have a python script to allow parsing certs over the network which can be very handy since it allows getting expiration dates for certs bound to servers and/OR VIPs

  6. Hey Carl,

    For the headers in my version of powershell, it threw an error (the content-type=application/vnd/etc)

    The fix was to use the -content-type [String] flag rather than the dictionary object to specify the content-type header. Hope this helps anyone else running into the error I was facing yesterday.

    For reference, the error was “The ‘content-Type’ header must be modified using the appropriate property or method.


Leave a Reply