1- The error is: "Unable to connect to vCloud server" 'The server returned the following: GatewayTimeout' , and i think this cause of our DCs in our environment.
-------------------------------------------
Original Message:
Sent: Jan 07, 2026 06:26 PM
From: ITSavant
Subject: PowerCLI Connect-CIServer to vCloud Director sometimes fails on first attempt (succeeds on retry), what best practice retry pattern?
I don't have a lab handy to test your code, that said:
1.) I'd be looking into why you have to reconnect, that along could be involved with the missing data. Wrong API version, network, certs, etc.
2.) -ErrorVariable will help you collect error messages and evaluate them
Original Message:
Sent: Jan 03, 2026 04:45 PM
From: Jermy CI
Subject: PowerCLI Connect-CIServer to vCloud Director sometimes fails on first attempt (succeeds on retry), what best practice retry pattern?
Hi everyone,
I'm running a scheduled DailyCheck PowerCLI report that connects to two vCloud Director environments and collects a few vCD-side items (vApp status, catalog/media, vApp network, cells), then generates an HTML report.
Two issues I want to improve:
- vCD login reliability: sometimes
Connect-CIServer fails temporarily, and I want to retry up to 3 times (with delay). - Report accuracy: currently some parts show "N/A" (because my HTML logic uses
?: "N/A" when the variable is empty). The problem is that "N/A" hides the real reason (authentication issue, etc.). I want the report to show the actual reason when data cannot be collected.
#connect vCloudDirectory
connect-Ciserver -server $cloudDirectorServer -Credential $credential
$vAppState_vCDss = Get-ciVApp -Name "daily-check-$today" -Orgvdc "S-Z-POD-Support" | Select-Object Name, Status
$CatalogMedia_vCDss = Get-Catalog -Name "daily-check-$today" -Org "Support"
$MediaItems_vCDss = Get-Media -Catalog "daily-check-$today" -server "x.x.x.x" | Select-Object Name, status
$vAppss = Get-OrgVdc -Name "S-Z-POD-Support" | Get-CIVApp -Name "daily-check-$today"
$vAppNetworkss = Get-CIVAppNetwork -VApp $vAppss
$vCenterss = Search-Cloud -QueryType virtualcenter -server xxxx | Select-Object Name, status,ListenerState
$sscell = Search-Cloud -QueryType cell -server xxxx | Select-Object Name, @{Name="IsActive";Expression={$_.IsActive ? "Active" : "Inactive"}}
Disconnect-CIServer -Server $cloudDirectorServer -Confirm:$false
Where "N/A" is coming from (HTML logic)
<td>$($CatalogMedia_vCDss ? "Created successfully" : "N/A")</td>
<td>$($MediaItems_vCDss ? "Upload successfully" : "N/A")</td>
<td>$($vAppNetworkss.Name ? $vAppNetworkss.Name : "N/A")</td>
<td>$($vAppNetworkss ? "Created successfully" : "N/A")</td>
My questions are
- What's the cleanest PowerCLI pattern to retry
Connect-CIServer up to 3 times (with delay) and avoid session leaks? - How turning "N/A" into a real failure reason? what's the cleanest way to capture and log the real failure reason from the PowerCLI exception?
Any guidance or examples would help a lot....
-------------------------------------------