This blog is a follow up to my last blog where I featured a powershell script for acquiring data for configured NetScaler Gateway virtual servers on a NetScaler appliance.  This article features a powershell script that acquires configuration data for Global Server Load Balancing.  If you haven’t read the last blog to this series, you can locate it here:

The script featured in this article will output data relating to a Content Switching virtual server.  Below is an example of the output:

Example Output

NetScaler Object Values
Global Service Load Balancing Configuration
GSLB Virtual Server Name: GSLB_vServer
GSLB Virtual Server Protocol: SSL
GSLB Virtual Server Method: STATICPROXIMITY
GSLB Virtual Server Backup Method: ROUNDROBIN
GSLB Virtual Server Domain Name: xlion
GSLB Service Name: SiteB_Service
GSLB Service Server Name: SiteB_AGEE
GSLB Service Server IP Address: 192.168.1.133
GSLB Service Port: 443
GSLB Service Protocol: SSL
GSLB Service Public IP Address: 192.168.1.133
GSLB Service Public Port: 443
GSLB Service State: ENABLED
GSLB Service Monitor Name:
GSLB Site Name: SiteB
GSLB Site Type: REMOTE
GSLB Site IP Address: 192.168.1.152
GSLB Site Public IP Address: 192.168.1.152
GSLB Site Metric Exchange: ENABLED
GSLB Site NWMetric Exchange: ENABLED
GSLB Site Session Exchange: ENABLED
GSLB Site Trigger Monitor: ALWAYS
GSLB Service Name: SiteA_Service
GSLB Service Server Name: 192.168.1.142
GSLB Service Server IP Address: 192.168.1.142
GSLB Service Port: 443
GSLB Service Protocol: SSL
GSLB Service Public IP Address: 192.168.1.142
GSLB Service Monitor Name: http-ecv tcp-ecv
GSLB Site Name: SiteA
GSLB Site Type: LOCAL
GSLB Site IP Address: 192.168.1.151
GSLB Site Public IP Address: 192.168.1.151
GSLB Site Metric Exchange: ENABLED
GSLB Site NWMetric Exchange: ENABLED
GSLB Site Session Exchange: ENABLED
GSLB Site Trigger Monitor: ALWAYS

Below are the main Nitro APIs utilized in the script:

[com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver] – Configuration for Global Server Load Balancing Virtual Server resource.

[com.citrix.netscaler.nitro.resource.config.gslb.gslbsite] – Configuration for GSLB site resource.

[com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_domain_binding] – Binding class showing the domain that can be bound to gslbvserver.

[com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_gslbservice_binding] – Binding class showing the gslbservice that can be bound to gslbvserver.

[com.citrix.netscaler.nitro.resource.config.gslb.gslbservice] – Configuration for GSLB service resource.

[com.citrix.netscaler.nitro.resource.config.gslb.gslbservice_lbmonitor_binding] – Binding class showing the lbmonitor that can be bound to gslbservice.

[com.citrix.netscaler.nitro.resource.config.gslb.gslbsite] – Configuration for GSLB site resource.

Below is the powershell script utilized to generate the output for GSLB virtual servers:

$nsip = ‘192.168.1.140’
$user = ‘nsroot’
$pass = ‘nsroot’
$path1 = “C:\Nitro\ns-10.1-122.17-sdk.tar\ns-10.1-122.17-sdk\ns_nitro-csharp_dara_122_17\lib\Newtonsoft.Json.dll”
$O = [System.Reflection.Assembly]::LoadFile($path1)
$path = “C:\Nitro\ns-10.1-122.17-sdk.tar\ns-10.1-122.17-sdk\ns_nitro-csharp_dara_122_17\lib\nitro.dll”
$O = [System.Reflection.Assembly]::LoadFile($path)
$nitrosession = new-object com.citrix.netscaler.nitro.service.nitro_service($nsip,”http”)
$session = $nitrosession.login($user,$pass)

$BeginHTMLTable = “<table border=1px width=800px>”
$EndHTMLTable = “</table>”
$BeginRow = “<tr>”
$EndRow = “</tr>”
$TableHeading = “<th>NetScaler Object</th> <th>Values</th>”
$HTMLFile = “c:\Scripts\NS_GSLB_HTML.htm”

$BeginHTMLTable | Add-Content $HTMLFile
$TableHeading | Add-Content $HTMLFile

$ALLGSLBvServers = [com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver]::get($nitrosession)
$AllGSLBSites = [com.citrix.netscaler.nitro.resource.config.gslb.gslbsite]::get($nitrosession)

$BeginRow | Add-Content $HTMLFile
“<td bgcolor=#808080> <font face=garamond>Global Service Load Balancing Configuration</font></td><td bgcolor=#808080></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

foreach ($a in $AllGSLBvServers)

{
$BeginRow | Add-Content $HTMLFile
$GSLBvName = $a.name
“<td> <font face=garamond>GSLB Virtual Server Name: </font></td><td><font face=garamond>” + $GSLBvName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBvProtocol = $a.servicetype
“<td> <font face=garamond>GSLB Virtual Server Protocol: </font></td><td><font face=garamond>” + $GSLBvProtocol + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBvLBMethod = $a.lbmethod
“<td> <font face=garamond>GSLB Virtual Server Method: </font></td><td><font face=garamond>” + $GSLBvLBMethod + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBvBackupMethod = $a.backuplbmethod
“<td> <font face=garamond>GSLB Virtual Server Backup Method: </font></td><td><font face=garamond>” + $GSLBvBackupMethod + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$GSLBDomainBinding = [com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_domain_binding]::get($nitrosession, $a.name)

foreach ($b in $GSLBDomainBinding)
{
$BeginRow | Add-Content $HTMLFile
$GSLBDomainName = $b.domainname
“<td> <font face=garamond>GSLB Virtual Server Domain Name: </font></td><td><font face=garamond>” + $GSLBDomainName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

} # I had to create this loop because the Domain Binding object was not exposing it’s properties.

$GSLBServiceBinding = [com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_gslbservice_binding]::get($nitrosession, $a.name)

foreach ($c in $GSLBServiceBinding)
{

$GSLBServiceObj = [com.citrix.netscaler.nitro.resource.config.gslb.gslbservice]::get($nitrosession, $c.servicename)
$GSLBServiceMonitor = [com.citrix.netscaler.nitro.resource.config.gslb.gslbservice_lbmonitor_binding]::get($nitrosession,$c.servicename)

$BeginRow | Add-Content $HTMLFile
$GSLBServiceName = $c.servicename
“<td bgcolor=#d3d3d3> <font face=garamond>GSLB Service Name: </font></td><td><font face=garamond>” + $GSLBServiceName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServerName = $GSLBServiceObj.servername
“<td> <font face=garamond>GSLB Service Server Name: </font></td><td><font face=garamond>” + $GSLBServerName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServiceIP = $c.ipaddress
“<td> <font face=garamond>GSLB Service Server IP Address: </font></td><td><font face=garamond>” + $GSLBServiceIP + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServicePort = $c.port
“<td> <font face=garamond>GSLB Service Port: </font></td><td><font face=garamond>” + $GSLBServicePort + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServiceProtocol = $c.servicetype
“<td> <font face=garamond>GSLB Service Protocol: </font></td><td><font face=garamond>” + $GSLBServiceProtocol + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServicePublicIP = $GSLBServiceObj.publicip
“<td> <font face=garamond>GSLB Service Public IP Address: </font></td><td><font face=garamond>” + $GSLBServicePublicIP + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServicePublicPort = $GSLBServiceObj.publicport
“<td> <font face=garamond>GSLB Service Public Port: </font></td><td><font face=garamond>” + $GSLBServicePublicPort + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServiceState = $GSLBServiceObj.state
“<td> <font face=garamond>GSLB Service State: </font></td><td><font face=garamond>” + $GSLBServiceState + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBServiceMonitorName = $GSLBServiceMonitor.monitor_name
“<td> <font face=garamond>GSLB Service Monitor Name: </font></td><td><font face=garamond>” + $GSLBServiceMonitorName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBSiteName = $GSLBServiceObj.sitename
“<td bgcolor=b0c4de> <font face=garamond>GSLB Site Name: </font></td><td><font face=garamond>” + $GSLBSiteName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBSiteType = $GSLBServiceObj.gslb
“<td> <font face=garamond>GSLB Site Type: </font></td><td><font face=garamond>” + $GSLBSiteType + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$GSLBSiteObj = [com.citrix.netscaler.nitro.resource.config.gslb.gslbsite]::get($nitrosession, $GSLBServiceObj.sitename)

$BeginRow | Add-Content $HTMLFile
$GSLBSiteIP = $GSLBSiteObj.siteipaddress
“<td> <font face=garamond>GSLB Site IP Address: </font></td><td><font face=garamond>” + $GSLBSiteIP + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBSitePublicIP = $GSLBSiteObj.publicip
“<td> <font face=garamond>GSLB Site Public IP Address: </font></td><td><font face=garamond>” + $GSLBSitePublicIP + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBSiteMEP = $GSLBSiteObj.metricexchange
“<td> <font face=garamond>GSLB Site Metric Exchange: </font></td><td><font face=garamond>” + $GSLBSiteMEP + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBNWMetric = $GSLBSiteObj.nwmetricexchange
“<td> <font face=garamond>GSLB Site NWMetric Exchange: </font></td><td><font face=garamond>” + $GSLBNWMetric + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBSessionExch = $GSLBSiteObj.sessionexchange
“<td> <font face=garamond>GSLB Site Session Exchange: </font></td><td><font face=garamond>” + $GSLBSessionExch + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$GSLBSiteTrigger = $GSLBSiteObj.triggermonitor
“<td> <font face=garamond>GSLB Site Trigger Monitor: </font></td><td><font face=garamond>” + $GSLBSiteTrigger + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile
} #End of GSLB Service Binding foreach loop.

} # End of GSLB Virtual Server loop.
$EndHTMLTable | Add-Content $HTMLFile

This article isn’t intended to teach powershell, but to provide a real-world example of how one could use powershell to generate powerful scripts to automate  tasks on the Citrix NetScaler, utilizing the Nitro API.

Note:  In order to view the script in it’s entirety, right click on the web page and click view page source.  Locate the script and copy and paste it into your favorite editor.

I hope you find this to be informative.