VMware Cloud Community
SebastianGrugel
Hot Shot
Hot Shot

Using PowerCli (11.5.0) to connect NSX Manager (6.4.6) by API

Hi i wanted connect to API to NSX Manager because i need get amount of session VPN SSL. This value i will need to ise inside script wchich willbe upgrade only EDGES without active users.

I used instruction from this book: https://subscription.packtpub.com/book/virtualization_and_cloud/9781786468017/14/ch14lvl1sec135/conn...

and created simple test on to estabilish connection but looks like something is not working and i dont understand why.

### Autorization

$NSXManager = 'NSXMANAGER'

$Username = 'admin'

$Password = 'PASSWORD'

###

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$Username`:$Password"))

$Headers = @{Authorization = "Basic $base64AuthInfo"}

###

#URI

$Uri = "https://$NSXManager/api/2.0/services/vcconfig"

$xml = Invoke-RestMethod -Uri $Uri -Method Get-Headers $Headers

$xm

pastedImage_1.png

Error:

Invoke-RestMethod : Cannot bind parameter 'Method'. Cannot convert value "Get-Headers" to type "Microsoft.PowerShell.Commands.WebRequestMethod". Error: "Unable to match the identifier name Get-Headers to a valid enumerator name. Specify one of the following enu

merator names and try again:

Default, Get, Head, Post, Put, Delete, Trace, Options, Merge, Patch"

At line:1 char:44

+ $xml = Invoke-RestMethod -Uri $Uri -Method Get-Headers $Headers

+                                            ~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

URI which i will use: https://NSXMANAGER/api/4.0/edges/edge-566/sslvpn/activesessions

Please about help.

vExpert VSAN/NSX/CLOUD | VCAP5-DCA | VCP6-DCV/CMA/NV ==> akademiadatacenter.pl
Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

I think you missed a blank in that line

$xml = Invoke-RestMethod -Uri $Uri -Method Get -Headers $Headers


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos