Update vCenter-SSL.ps1
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
#!/usr/bin/env pwsh
|
#!/usr/bin/env pwsh
|
||||||
# -----------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------
|
||||||
# vCenter + Posh-ACME Script (Linux/macOS-safe)
|
# vCenter + Posh-ACME Script (Linux/macOS-safe, fixed HTTP content read)
|
||||||
# - Uses -SkipCertificateCheck to bypass SSL validation
|
|
||||||
# - Proper ErrorRecord handling
|
|
||||||
# - PowerDNS plugin uses plain string API key
|
|
||||||
# - Fault-tolerant ACME certificate handling
|
|
||||||
# -----------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
. /opt/idssys/nodemgmt/conf/powerwall/settings.ps1
|
. /opt/idssys/nodemgmt/conf/powerwall/settings.ps1
|
||||||
@@ -109,14 +105,15 @@ if (-not (Get-Module -ListAvailable -Name Posh-ACME)) {
|
|||||||
Import-Module Posh-ACME -ErrorAction Stop
|
Import-Module Posh-ACME -ErrorAction Stop
|
||||||
|
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# Connect to vCenter API
|
# Connect to vCenter API using Invoke-WebRequest
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
$loginUri = "https://$vCenterURL/rest/com/vmware/cis/session"
|
$loginUri = "https://$vCenterURL/rest/com/vmware/cis/session"
|
||||||
Write-Host "Connecting to vCenter at $vCenterURL ..." -ForegroundColor Cyan
|
Write-Host "Connecting to vCenter at $vCenterURL ..." -ForegroundColor Cyan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$sessionResponse = Invoke-SafeRestMethod -Uri $loginUri -Method Post -Headers @{}
|
$resp = Invoke-WebRequest -Uri $loginUri -Method Post -SkipCertificateCheck -UseBasicParsing -Headers @{}
|
||||||
$sessionToken = $sessionResponse.value
|
$json = $resp.Content | ConvertFrom-Json
|
||||||
|
$sessionToken = $json.value
|
||||||
if (-not $sessionToken) {
|
if (-not $sessionToken) {
|
||||||
throw [System.Exception] "Unable to obtain vCenter session token"
|
throw [System.Exception] "Unable to obtain vCenter session token"
|
||||||
}
|
}
|
||||||
@@ -136,7 +133,7 @@ try {
|
|||||||
} catch { Write-Host "Unable to retrieve VM list, continuing..." -ForegroundColor Yellow }
|
} catch { Write-Host "Unable to retrieve VM list, continuing..." -ForegroundColor Yellow }
|
||||||
|
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# Fault-tolerant ACME certificate request
|
# ACME certificate request
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
$certName = "vcenter-cert"
|
$certName = "vcenter-cert"
|
||||||
$certSuccess = $false
|
$certSuccess = $false
|
||||||
|
|||||||
Reference in New Issue
Block a user