How it works...

In this example, we used the built-in Invoke-WebRequest cmdlet to perform HTTP GET and HTTP POST requests from PowerShell. PowerShell is available on the Windows platform; for non-Windows platforms, such as macOS and Linux, you can use PowerShell Core: https://aka.ms/getps6-linux.

In this example, we store all the required values, such as the FQDN or IP of NSX Manager, URL, headers, and credentials, in variables so they can be reused:

# NSX Variables $NSXUsername = "admin" $NSXPassword = "VMware1!" $NSXManager = "https://nsxmgr-01a.corp.local" $NSXURI = "/api/2.0/services/usermgmt/user/admin" # NSX Authorization Header $NSXAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NSXUsername + ":" + $NSXPassword)) ...

Get VMware NSX Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.