PowerShell: Import the NetScaler VPX with a fixed IP-address on XenServer


During the preparations of my presentation with Hendricus Kramer on NetScaler Automation with Puppet at E2EVC in Lisbon, I used a lot of PowerShell scripts to test the interaction with NetScaler’s NITRO. Where Hendricus is the Puppet Expert, I’m having a lot of fun building PowerShell scripts to automate deployments and common administrative tasks. I’m no PowerShell expert and my code can probably be improved in many ways, it does however get the job done (and offers a great learning experience as I improve with every script I built).

At the Dutch Citrix User Group meeting I was talking with Sander Bierman and sharing my enthusiasm on automating the NetScaler configuration with NITRO and PowerShell. We both agreed that NITRO offers many possibilities to automate the NetScaler configuration, but still requires you to provide a NetScaler IP-address to connect. “Wouldn’t it be great if you could automatically deploy a NetScaler VPX with a given IP-address, to automate the NetScaler deployment on your Hypervisor as well” I asked Sander. He just smiled and told me the answer could be found in a Citrix KnowledgeBase article! And those of you that attended his session, know he also found the answer to script a NetScaler VPX deployment on vSphere with a fixed IP-address.

So let me share the PowerShell script I created to do this for XenServer!


CTX128236: How To Auto-Provision NetScaler VPX on XenServer

There is a great Citrix KnowledgeBase article on How To Auto-Provision NetScaler VPX on XenServer that offers a step-by-step guide on how to import a NetScaler VPX onto XenServer and provide it with a pre-configured NetScaler IP-address, using the CommandLine Interface (CLI) of XenServer. Even though the instructions are very clear, I needed more than just the xe commands to make it work. So I decided to translate the instructions to my new favorite scripting language: PowerShell.


The XenServer 6.5.1 SDK

To create a PowerShell script for the given instructions in the above mentioned article, I downloaded the XenServer 6.5.1 SDK that includes a PowerShell Module. So with the PowerShell Module at hand I could simply translate the instructions into the right PowerShell cmdlets and build my script.


My PowerShell script

So without further ado, here’s my PowerShell script to automatically import a NetScaler VPX in XenServer and give it a fixed NetScaler IP-address:

# based upon CTX article: http://support.citrix.com/article/CTX128236
# Import XenServer 6.5.1 SDK
Import-Module "C:\PSModules\XenServerPSModule"

# Configure script variables
$XSServer = ""                                    # Hostname or IP-address of XenServer Poolmaster
$sourcePath = ".\NSVPX-XEN-11.0-63.16_nc.xva"                  # location of NS VPX image on machine running PowerShell
$nsIPAddress = ""                                  # fixed IP-address to configure for the NetScaler VPX
$nsNetmask = ""                                   # Netmask to configure for the NetScaler VPX
$nsGateway = ""                                    # Default Gateway to configure for the NetScaler VPX

# Open a connection to XenServer (poolmaster) and make it the default session (required)
$oXSSession = Connect-XenServer -Server $XSServer -SetDefaultSession

# Import the NetScaler image to the default SR
Import-XenVm -XenHost $XSServer -Path $sourcePath

# Get the imported NS VPX VM uuid by it's default name
$oVM = Get-XenVM -Name "NetScaler Virtual Appliance"

# Change the name of the VM
Set-XenVM -Uuid $oVM.uuid -NameLabel "NetScaler VPX"

# Get current VM XenStoreData values
$newHash = $oVM.xenstore_data

# Add required values for fixed IP settings for the NetScaler VPX

# Add new values to current VM XenStoreData (works only once, before NS is booted)
Set-XenVM -VM $oVM -XenstoreData $newHash

# Start the NS Appliance
Invoke-XenVM $oVM -XenAction Start

# Disconnect the session
Get-XenSession -Server $XSServer | Disconnect-XenServer


This blogpost was created to share the bonus content of the NetScaler Automation presentation by Hendricus Kramer and myself at E2EVC Lisbon.


And here’s the recorded demo video:

With a big thanks to TechSmith for providing me with a copy of Camtasia for the recording.


The following sources have been used to create this post:
How To Auto-Provision NetScaler VPX on XenServer
XenServer SDK Overview



Esther Barthel
Solutions Architect at cognition IT

Esther has been working in different roles and functions as an IT consultant ever since she finished her Masters degree in Computer Science in 1997. She has worked as a web developer, database administrator, and server administrator until she discovered how Server-Based Computing ( SBC ) combined servers, desktops, and user experience in one solution. Esther has been specializing in virtualization solutions such as SBC, VDI, application, and server virtualization for over eight years now and is currently working as a Senior Consultant at PepperByte, where she designs and implements Citrix® solutions for both small-business and large-enterprise infrastructures scaling from 100 to 15,000 users.
In january 2014 her first book Citrix XenApp 6.5 Expert Cookbook was published by Packt Publishing.

Esther is awarded as a Citrix Technology Professional (CTP) from 2015 - 2017.
Esther is awarded as a Microsoft Most Valuable Professional (MVP) in 2017.

Esther is a Citrix Certified Expert – Virtualization (CCE-V), Citrix Certified Professional – Mobility (CCP-M), Citrix Certified Professional – Networking (CCP-N) and RES Software Certified Professional (RCP).