This blog is a follow up to my last blog where I featured a powershell script for acquiring data for configured Global Server Load Balancing virtual servers on a NetScaler appliance.  This article features a powershell script that acquires configuration data for Networking.  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
Citrix NetScaler Networking Configuration
Interface
Interface Name: 1-Jan
Interface Alias:
Interface State: ENABLED
Interface Description: NetScaler Virtual Interface
Interface HA Monitor: ON
Interface VLAN: 1
Interface Tagging: OFF
Interface MAC Address: 8a:b7:a7:f1:f0:24
Interface
Interface Name: LA/1
Interface Alias:
Interface State: ENABLED
Interface Description: 802.3ad Link Aggregate
Interface HA Monitor: ON
Interface VLAN: 1
Interface Tagging: OFF
Interface MAC Address: ba:36:06:7e:3e:43
Interface
Interface Name: LO/1
Interface Alias:
Interface State: ENABLED
Interface Description: Netscaler Loopback interface
Interface HA Monitor: OFF
Interface VLAN: 1
Interface Tagging: OFF
Interface MAC Address: 8a:b7:a7:f1:f0:24
Link Aggregated Channel
Channel Name: LA/1
Channel State: ENABLED
Channel Description: 802.3ad Link Aggregate
Channel VLAN: 1
Channel MAC Address: ba:36:06:7e:3e:43
Channel Interfaces:
Network routes
Network: 0.0.0.0
Netmask: 0.0.0.0
Gateway: 192.168.1.1
Network routes
Network: 127.0.0.0
Netmask: 255.0.0.0
Gateway: 127.0.0.1
Network routes
Network: 192.168.1.0
Netmask: 255.255.255.0
Gateway: 192.168.1.140
VLAN Info
VLAN ID: 1
VLAN Alias Name:
VLAN Interfaces: LO/1 LA/1
VLAN Tagged Interfaces:

Below are the main Nitro APIs utilized in the script:

[com.citrix.netscaler.nitro.resource.config.network.Interface] – Configuration for interface resource.

[com.citrix.netscaler.nitro.resource.config.network.Channel] – Configuration for channel resource.

[com.citrix.netscaler.nitro.resource.config.network.route] – Configuration for route resource.

[com.citrix.netscaler.nitro.resource.config.network.vlan] – Configuration for “VLAN” resource.

Below is the powershell script utilized to generate the output for Networking:

$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_Networking_HTML.htm”

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

$AllInterfaces = [com.citrix.netscaler.nitro.resource.config.network.Interface]::get($nitrosession)

$BeginRow | Add-Content $HTMLFile
“<td bgcolor=#808080><font face=garamond color=white>Citrix NetScaler Networking Configuration</font></td><td bgcolor=#808080><font face=garamond></font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

foreach ($a in $AllInterfaces)

{
$BeginRow | Add-Content $HTMLFile
“<td bgcolor=#808080><font face=garamond color=white>Interface </font></td><td bgcolor=#808080><font face=garamond></font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceName = $a.id
“<td><font face=garamond>Interface Name: </font></td><td><font face=garamond>” + $InterfaceName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceAlias = $a.ifalias
“<td><font face=garamond>Interface Alias: </font></td><td><font face=garamond>” + $InterfaceAlias + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceState = $a.state
“<td><font face=garamond>Interface State: </font></td><td><font face=garamond>” + $InterfaceState + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceDescription = $a.description
“<td><font face=garamond>Interface Description: </font></td><td><font face=garamond>” + $InterfaceDescription + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceHAMonitor = $a.hamonitor
“<td><font face=garamond>Interface HA Monitor: </font></td><td><font face=garamond>” + $InterfaceHAMonitor + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceVLAN = $a.vlan
“<td><font face=garamond>Interface VLAN: </font></td><td><font face=garamond>” + $InterfaceVLAN + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceTagall = $a.tagall
“<td><font face=garamond>Interface Tagging: </font></td><td><font face=garamond>” + $InterfaceTagall + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$InterfaceMAC = $a.mac
“<td><font face=garamond>Interface MAC Address: </font></td><td><font face=garamond>” + $InterfaceMAC + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

}
$AllChannels = [com.citrix.netscaler.nitro.resource.config.network.Channel]::get($nitrosession)

foreach ($b in $AllChannels)

{
$BeginRow | Add-Content $HTMLFile
“<td bgcolor=#808080><font face=garamond color=white>Link Aggregated Channel </font></td><td bgcolor=#808080><font face=garamond></font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$LAChannelName = $b.id
“<td><font face=garamond>Channel Name: </font></td><td><font face=garamond>” + $LAChannelName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$LAState = $b.state
“<td><font face=garamond>Channel State: </font></td><td><font face=garamond>” + $LAState + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$LADescription = $b.description
“<td><font face=garamond>Channel Description: </font></td><td><font face=garamond>” + $LADescription + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$LAVLAN = $b.vlan
“<td><font face=garamond>Channel VLAN: </font></td><td><font face=garamond>” + $LAVLAN + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$LAMAC = $b.mac
“<td><font face=garamond>Channel MAC Address: </font></td><td><font face=garamond>” + $LAMAC + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$LAInt = $b.ifnum
“<td><font face=garamond>Channel Interfaces: </font></td><td><font face=garamond>” + $LAInt + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

} #end of Channel loop.

$AllRoutes = [com.citrix.netscaler.nitro.resource.config.network.route]::get($nitrosession)

foreach ($c in $AllRoutes)
{
$BeginRow | Add-Content $HTMLFile
“<td bgcolor=#808080><font face=garamond color=white>Network routes </font></td><td bgcolor=#808080><font face=garamond></font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$Network = $c.network
“<td><font face=garamond>Network: </font></td><td><font face=garamond>” + $Network + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$Netmask = $c.netmask
“<td><font face=garamond>Netmask: </font></td><td><font face=garamond>” + $Netmask + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$Gateway = $c.gateway
“<td><font face=garamond>Gateway: </font></td><td><font face=garamond>” + $Gateway + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile
} # end of Route loop.
$AllVLANs = [com.citrix.netscaler.nitro.resource.config.network.vlan]::get($nitrosession)

foreach ($d in $AllVLANs)
{
$BeginRow | Add-Content $HTMLFile
“<td bgcolor=#808080><font face=garamond color=white>VLAN Info </font></td><td bgcolor=#808080><font face=garamond></font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$VLANID = $d.id
“<td><font face=garamond>VLAN ID: </font></td><td><font face=garamond>” + $VLANID + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$AliasName = $d.aliasname
“<td><font face=garamond>VLAN Alias Name: </font></td><td><font face=garamond>” + $AliasName + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$VLANInterfaces = $d.ifaces
“<td><font face=garamond>VLAN Interfaces: </font></td><td><font face=garamond>” + $VLANInterfaces + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

$BeginRow | Add-Content $HTMLFile
$BLANTaggedInterfaces = $d.tagifaces
“<td><font face=garamond>VLAN Tagged Interfaces: </font></td><td><font face=garamond>” + $BLANTaggedInterfaces + “</font></td>” | Add-Content $HTMLFile
$EndRow | Add-Content $HTMLFile

}
$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.