Requesting the HTTP POST REST API via PowerShell

In this example, we will create a logical switch using the HTTP POST REST API request via PowerShell:

  1. For HTTP POST, change the -Method to Post and include an XML payload using the -Body option, as follows:
# NSX Variables $NSXUsername = "admin" $NSXPassword = "VMware1!" $NSXManager = "https://nsxmgr-01a.corp.local" $NSXURI = "/api/2.0/vdn/scopes/vdnscope-1/virtualwires" # NSX Authorization Header $NSXAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NSXUsername + ":" + $NSXPassword)) $NSXAuthHeader = @{"Authorization"="Basic $NSXAuth"} # NSX XML Payload [xml]$XMLBody = "<virtualWireCreateSpec> <name>PowerShell-Logical-Switch</name> <description>Logical Switch ...

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.