TheAI Stack

FIELD NOTES BY AVNISH TRIPATHI

Fed days back one of my close friend working with a customer , whose NSX environment is  cross–vCenter NSX environment , because of this they have to create IP sets as IP Sets are the universal objects which get synchronized with secondary instance of NSX. since this IP Sets list was big so we were looking for automating using NSX API but don’t want to make many API calls manually , so we have decided to do it using PowerShell way and we decided to use Invoke-RestMethod , which was introduced in PowerShell 3.0

Invoke-RestMethod

The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that returns richly structured data.Windows PowerShell formats the response based to the data type. For an RSS or ATOM feed, Windows PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, Windows PowerShell converts (or deserializes) the content into objects.

CSV File Format used in Script:

1.GIF

Script to Create IP Sets from CSV is as below:

2

Result:

3

4

Finally ,using Invoke-RestMethod or Invoke-WebRequest , we can automate many of routine tasks of NSX using PowerShell. Hope this helps in your daily routine administrative tasks  :).

 

THE AI STACK · BY EMAIL

Get the next field note

New guides on private cloud, Kubernetes and enterprise AI, delivered when I publish. Subscribe free and unsubscribe anytime.

Enter your email and confirm your subscription in the message from WordPress.com.

Comments

Leave a Reply

The AI Stack · Independent field notes by Avnish Tripathi

About   /   Contact