Skip to content

Tag: Module

PoSh – Gathering VMware NSX Info via API

I’ve been lucky enough to get a chance to do some work involving VMware’s NSX product lately. Having watched a bunch of VMworld sessions, live demos and messed around with it in the VMware Hands on Labs I was fairly comfortable in an existing environment. However I’ve gotten fairly used to using Powershell to do most of my work and there doesn’t appear to be much out there in the way of cmdlets or functions.

Chris Wahl has some really good resources regarding using Powershell to do API calls with NSX to both gather controller information (Creating NSX API Calls with PowerShell – Wahl Network) and create/remove virtual network tiers (Leveraging PowerShell to Deploy Virtual Network Tiers with VMware NSX – Wahl Network).

Thanks to Chris’ first post, I’ve taken what he created and built out a couple additional functions and even dumped them all into module form.

An overview of what’s currently included in the module:

Function Name Description
Get-NSXController Will inventory all of your controllers from NSX Manager
Get-NSXController
Get-NSXEdges Will inventory all of your Edge Nodes from NSX Manager
Get-NSXEdges
Get-NSXEdgeFeatures Will inventory all of your Edge Nodes’ Features from NSX Manager
Get-NSXEdgeFeatures
Get-NSXEdgeInterfaces Will inventory the selected Edge Node’s Interfaces from NSX Manager
Get-NSXEdgeInterfaces
Get-NSXEdgeNats Will inventory all of your Edge Node’s NATs from NSX Manager
Get-NSXEdgeNATs
Get-NSXEdgeRoutingOverview Will inventory all of your Edge Nodes’ Routing Overview details from NSX Manager
Get-NSXEdgeRoutingOverview
Get-NSXUplinks Will inventory all of your Edge Nodes’ Uplinks from NSX Manager
Get-NSXEdgeUplinks

A general walk-through of what’s occurring within each function is Powershell using the Invoke-WebRequest cmdlet against the NSX Manager’s REST API and formatting what’s returned into an easy to consume format that is a similar match to what’s returned back by way of the “Networking and Security” plugin.

Requirements:
Powershell 3.0 or better: Invoke-WebRequest first appeared in Powershell version 3.0, so anything less won’t work.
NSX Manager Admin credentials: All of the information is being pulled directly from the NSX Manager
Import the module by way of the .psd1 file: while not really a requirement, it certainly helps with the formatting of the output

Example of how the formatting is handled, first with the .psd1 file then with the .psm1 file:
Loading NSX PSD1 vs PSM1

Link to the GitHub repo location: https://github.com/kmruddy/Powershell/tree/master/Modules/NSXModule

An automated way of downloading the files into a dedicated directory and importing the module into the current session:

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.