Connect-CIServer VCF PowerCLI cmdlet to connect to a VMware Cloud Director (VCD) instance.Connect-CIServer cmdlet has no option to provide an API Access Token as the authentication credential.Connect-CIServer cmdlet does have an option to provide a SessionID in the form of "Bearer ####..." as the authentication credential.To use an API Access Token with the Connect-CIServer cmdlet, first log into the VCD token API endpoint using the PowerShell Invoke-RestMethod cmdlet, and then use the token in the form of "Bearer ###..." as the SessionID in the Connect-CIServer PowerCLI cmdlet.
Example steps would be as follows:
Generate an API Token as either a System level user in the VCD Provider portal, or as an Organization level user in the VCD Tenant portal, under User Preferences > API Tokens > New after logging in as that user.
For more information see the respective documentation:
Generate an API Access Token Using Your VMware Cloud Director Service Provider Admin Portal
Generate an API Access Token Using Your VMware Cloud Director Tenant Portal
Retain this generated API Token, for example:
############################1234
In PowerShell use the standard Invoke-RestMethod cmdlet to log into VCD via the VCD token API and save the response in a variable.
Use the API Token from steps 1. and 2. above as the refresh_token in the log in request to the the VCD token API, for example:
For a System level Provider user:$token = Invoke-RestMethod -Method POST -Uri "https://vcd.example.com/oauth/provider/token?grant_type=refresh_token&refresh_token=############################1234"
For an Organization level Tenant user:$token = Invoke-RestMethod -Method POST -Uri "https://vcd.example.com/oauth/tenant/<organization_name>/token?grant_type=refresh_token&refresh_token=############################1234"
This $token variable now includes the Bearer Token for our login in the $token.access_token value, for example:
####...
Use the SessionID option in the PowerCLI Connect-CIServer cmdlet to connect to VCD with this Bearer Token instead of a username and password, for example:
Connect-CIServer -Server vcd.example.com -SessionID "Bearer $($token.access_token)"
After the Connect-CIServer completes, further PowerCLI cmdlets to interact with VCD can be run.
For example to list to the vApps accessible to the logged in user, the Get-CIVApp cmdlet could be run:
Get-CIVApp
To disconnect from VCD the PowerCLI Disconnect-CIServer cmdlet can be run, for example:
Disconnect-CIServer -Server vcd.example.com