Categories
Web

Connect-CIServer: Invalid API version requested

Recently my script stopped working to connect to vCloudDirector. I consume vCloudDirector from a managed service company and sometimes the version changes without me knowing or having a simple way to check it. Just now this happened to me again, usually this then means my PowerCLI script starts failing.

Connect-CIServer : 30.04.2025 10:17:40	Connect-CIServer		NOT_ACCEPTABLE: The request has invalid accept header: Invalid API version requested. Supported API versions are: [38.0.0-alpha, 37.3, 37.2, 37.1, 37.0, 36.3, 
36.2, 36.1, 36.0, 35.2 [D], 35.0 [D], 34.0 [D], 33.0 [D]] ([D] indicates deprecated versions)	
At line:25 char:1
+ Connect-CIServer -Server ("https://{0}" -f $vcd) -SessionId Bearer $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-CIServer], CIServerException
    + FullyQualifiedErrorId : Cloud_ConnectivityServiceImpl_ConnectCloudServer_BySessionId_ConnectError,VMware.VimAutomation.Cloud.Commands.Cmdlets.ConnectCIServer

A simple install or update module didn’t work.

Install-Module -Name VMware.PowerCLI
Update-Module -Name VMware.PowerCLI

I was faced with the following errors.

PackageManagement\Install-Package : Authenticode issuer 'CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert
Inc, C=US' of the new module 'VMware.VimAutomation.Cloud' with version '13.3.0.24145081' is not matching with the
authenticode issuer 'CN=VeriSign Class 3 Public Primary Certification Authority - G5, OU="(c) 2006 VeriSign, Inc. -
For authorized use only", OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US' of the previously-installed module
'VMware.VimAutomation.Cloud' with version '12.0.0.15940183'. If you still want to install or update, use
-SkipPublisherCheck parameter.
At C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package],
   Exception
    + FullyQualifiedErrorId : AuthenticodeIssuerMismatch,Validate-ModuleAuthenticodeSignature,Microsoft.PowerShell.Pac
   kageManagement.Cmdlets.InstallPackage

After reviewing, I was not concerned that the signing authority changed. Therefore, I went ahead and installed the latest version by skipping the publisher check.

Install-Module -Name VMware.PowerCLI -SkipPublisherCheck -Force

And boom, this let me again connect to the vCloud Director with powercli.

# Settings
$vcd = 'vcd.web-performance.ch'
$org = 'wpch'
# Personal Access Token, get it from here https://vcd.web-performance.ch/tenant/wpch/administration/settings/user-preferences
$token = ''
 
 
if($token.Length -le 0) {
    throw "No token specified in settings."
}
 
$uri = "https://$($vcd)/oauth/tenant/$($org)/token?grant_type=refresh_token&refresh_token=$($token)"
$response = Invoke-Restmethod -method Post -Uri $uri -Headers @{'Accept' = 'application/json'} 
$authtoken = "Bearer " + $response.access_token 

Connect-CIServer -Server ("https://{0}" -f $vcd) -SessionId Bearer $($response.access_token)
 
# All VM
# https://developer.vmware.com/docs/powercli/latest/products/vmwareclouddirector/categories/civm/
$vms = Get-CIVM 
$vms | Format-Table

# Disconnects all default servers without asking for confirmation.
# https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.cloud/commands/disconnect-ciserver/#Default
Disconnect-CIServer -Server ("https://{0}" -f $vcd) -Confirm:$false

More