Requesting the HTTP GET REST API via PowerShell

In this example, we will perform an HTTP GET REST API request via PowerShell:

  1. Open a text editor, input the following code, and save it into a .ps1 extension, for example NSX-PowerShellGET.ps1:
# 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)) $NSXAuthHeader = @{"Authorization"="Basic $NSXAuth"} # Add code to allow untrusted SSL certs - taken from https://d-fens.ch/2013/12/20/nobrainer-ssl-connection-error-when-using-powershell/ Add-Type ...

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.