NetScaler Scripting

Last Modified: Jan 4, 2018 @ 8:14 am

Navigation

ūüí° = Recently Updated

Changelog

  • 2018 Jan 4 – For 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 Configuration Extractor

New and improved NetScaler Configuration Extractor. This time using PowerShell. Here are some features of the script:

  • Given a ns.conf file, the script extracts CLI commands for one or more Virtual Servers.
  • Given a Virtual Server name, the script enumerates all objects linked to the Virtual Server (e.g. Responder Policies) and provides their configuration too.
  • Finds global settings that might affect the operation of the chosen Virtual Servers.
  • The CLI output is listed in proper order. For example, create monitors before binding them to Service Groups.
  • If an exact Virtual Server name is not specified in the script, then the script will prompt you to select one or more Virtual Servers. The list of Virtual Servers can be filtered.

The extracted Virtual Server CLI configuration can be used for documentation, or to apply the configuration to a different appliance.

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 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 https://github.com/cognitionIT/PS-NITRO. See Citrix Synergy TV РSYN325 РAutomating NetScaler: talking NITRO with PowerShell for an overview.

The below NetScalerPowerShell.zip 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.

11 thoughts on “NetScaler Scripting”

  1. 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.

    Thanks
    Leo

      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.

  2. 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.

    -Trey

Leave a Reply