VMware PowerCLI 13.1 and API Tokens

I previously wrote here and here about using the new VMware Cloud Director (VCD) API tokens functionality first introduced in version 10.3.1 to allow scripts and automation to connect to a VCD environment. With the update to VMware PowerCLI version 13.1 the previous way of achieving this is deprecated as the x-vcloud-authorization header is no longer used as VMware continue the move to cloudapi and now instead we can simply use a bearer token.

This actually simplifies connecting to VCD using PowerCLI with an API token, but means that the script I previously published here won’t work with PowerCLI versions 13.1 (or later). I’ve now renamed the vcd-token.ps1 script in github to vcd-token-legacy.ps1 which should only be used on PowerCLI versions 13.0 and prior, for PowerCLI version 13.1 and later the replacement vcd-token.ps1 should now be used.

I’ve also added a script option to skip verification of SSL certificate checks which can be useful while testing in non-production environments.

If you just want to use this in your scripting or automation workflows then simply grab this code and include/adjust it as necessary for your environment.

I’ve tested this using PowerCLI 13.1, PowerShell Core 7.3.6 against a test VCD environment running the recently released version 10.5 where it all works fine, but any version of PowerCLI 13.1+ and VCD 10.3.1+ should also be fine.

As always, any comments/feedback welcome, and if you have issues please feel free to raise an issue against my github repository.

Jon

Tagged , , , . Bookmark the permalink.

3 Responses to VMware PowerCLI 13.1 and API Tokens

  1. Stefan Gut says:

    Hello Jon,

    I need to do some testing but looks like you have shown exactly what I need to connect powercli to vCD. Much appreciated.

  2. Stefan Gut says:

    I have this working, thanks for putting this up on the web, you have been most helpful.

    Look me up if you’re ever in Melbourne, Aus I owe you a beer!

  3. Yannick says:

    I kept getting the following error:

    Connect-CIServer : Connect-CIServer Unable to connect to vCloud Server ‘https://:443/api/’. The server returned the following: Unauthorized: ”.

    Your script helped me solve this, thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

4 − three =