Search code examples
powershellvspherepowercli

Getting an error with Connect-NsxServer with powershell PowerNSX module


after running this command

$cred = get-credential
Connect-NsxServer -vCenterServer MyVsphereServer -Credential $cred

I get this error

Connection to NSX server 10.X.X.X failed : Invoke-NsxRestMethod : The NSX API response received indicates a failure. 403 : Forbidden : Response Body: 
At C:\Program Files\WindowsPowerShell\Modules\PowerNSX\3.0.1174\PowerNSX.psm1:4939 char:13
+             Throw "Connection to NSX server $NsxServer failed : $_"
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Connection to N...Response Body: :String) [], RuntimeException
    + FullyQualifiedErrorId : Connection to NSX server 10.X.X.X failed : Invoke-NsxRestMethod : The NSX API response received indicates a failure. 403 : Forbidden : Respons 
   e Body: 

I see this in the error, but have never set this before either

The variable '$defaultNSXConnection' cannot be retrieved because it has not been set.

The PowerNSX module comment says:

 Invoke-NsxWebRequest uses either a specified connection object as returned
    by Connect-NsxServer, or the $DefaultNsxConnection global variable if
    defined to construct a REST api call to the NSX API.

My account permissions can't be the issue. I can log into the NSX gui and have enterprise admin creds. I can also successfully log into Vsphere with powercli module and run cmdlets against it. It's specifically when I try to connect to NSX that I get an error. Lost at this point. Not sure why it won't work. Tried by IP and FQDN. the -vcenterserver parameter is prefered according to their documenation, and I do see Green text response directing to the correct nsx manager IP address. Everything looks right, but clearly something isn't.


Solution

  • powernsx apparently REQUIRES you to use the [email protected] account to use it, regardless if your other admin account can make any API call supported by NSX with native API calls.

    Didn't see that in the powernsx documentation. If it's not just an oversite on my part, that really should be front and center in their docs.