Update vCenter-SSL.ps1
This commit is contained in:
@@ -49,10 +49,10 @@ function Show-Failure {
|
||||
param([System.Management.Automation.ErrorRecord]$ErrorRecord)
|
||||
$msg = $ErrorRecord.Exception.Message
|
||||
|
||||
Write-Log ERROR $msg -ForegroundColor Red
|
||||
Write-Host "======================================================" -ForegroundColor Red
|
||||
Write-Host "ERROR: $msg" -ForegroundColor Red
|
||||
Write-Host "======================================================" -ForegroundColor Red
|
||||
Write-Log ERROR $msg Red
|
||||
Write-Host "======================================================" Red
|
||||
Write-Host "ERROR: $msg" Red
|
||||
Write-Host "======================================================" Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ try {
|
||||
if (-not (Get-Module -ListAvailable -Name Posh-ACME)) {
|
||||
Install-Module Posh-ACME -Force -Scope AllUsers
|
||||
}
|
||||
Import-Module Posh-ACME -ErrorAction Stop *>$null -ForegroundColor Red
|
||||
Import-Module Posh-ACME -ErrorAction Stop *>$null
|
||||
Write-Log INFO "Posh-ACME loaded."
|
||||
} catch { Show-Failure $_ }
|
||||
|
||||
@@ -105,7 +105,7 @@ try {
|
||||
$vms = Get-VM
|
||||
Write-Log INFO "Retrieved $($vms.Count) VMs from vCenter."
|
||||
} catch {
|
||||
Write-Log WARN "Failed to enumerate VMs: $($_.Exception.Message)" -ForegroundColor Orange
|
||||
Write-Log WARN "Failed to enumerate VMs: $($_.Exception.Message)" Orange
|
||||
}
|
||||
|
||||
# ----------------------------
|
||||
@@ -124,7 +124,7 @@ try {
|
||||
Select-Object -First 1
|
||||
}
|
||||
} catch {
|
||||
Write-Log WARN "Failed to query Posh-ACME certificates: $($_.Exception.Message)" -ForegroundColor Orange
|
||||
Write-Log WARN "Failed to query Posh-ACME certificates: $($_.Exception.Message)" Orange
|
||||
}
|
||||
|
||||
if ($paCert) {
|
||||
@@ -139,7 +139,7 @@ if ($paCert) {
|
||||
$needNewCert = $false
|
||||
}
|
||||
} else {
|
||||
Write-Log WARN "No existing cert found — issuance required." -ForegroundColor Orange
|
||||
Write-Log WARN "No existing cert found — issuance required." Orange
|
||||
$needNewCert = $true
|
||||
}
|
||||
|
||||
@@ -172,17 +172,17 @@ if ($needNewCert) {
|
||||
$paCert = Get-PACertificate
|
||||
Write-Log INFO ("New certificate issued: NotAfter={0}" -f $paCert.NotAfter)
|
||||
} catch {
|
||||
Write-Log ERROR ("ACME issuance failed: {0}" -f $_.Exception.Message) -ForegroundColor Red
|
||||
Write-Log ERROR ("ACME issuance failed: {0}" -f $_.Exception.Message) Red
|
||||
if (-not $paCert) {
|
||||
Write-Log ERROR "No fallback certificate exists — aborting." -ForegroundColor Red
|
||||
Write-Log ERROR "No fallback certificate exists — aborting." Red
|
||||
exit 1
|
||||
}
|
||||
Write-Log WARN "Using existing Posh-ACME certificate." -ForegroundColor Orange
|
||||
Write-Log WARN "Using existing Posh-ACME certificate." Orange
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $paCert) {
|
||||
Write-Log ERROR "No usable certificate available — aborting." -ForegroundColor Red
|
||||
Write-Log ERROR "No usable certificate available — aborting." Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ if ($needNewCert) {
|
||||
|
||||
foreach ($f in @($certPath,$keyPath,$chainPath)) {
|
||||
if (-not (Test-Path $f)) {
|
||||
Write-Log ERROR "Missing cert file: $f" -ForegroundColor Red
|
||||
Write-Log ERROR "Missing cert file: $f" Red
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
@@ -240,7 +240,7 @@ if ($needNewCert) {
|
||||
$needPush = $false
|
||||
}
|
||||
} catch {
|
||||
Write-Log WARN "Unable to read vCenter cert, assuming update required." -ForegroundColor Orange
|
||||
Write-Log WARN "Unable to read vCenter cert, assuming update required." Orange
|
||||
}
|
||||
|
||||
# ----------------------------
|
||||
@@ -257,7 +257,7 @@ if ($needNewCert) {
|
||||
Set-VIMachineCertificate -PemCertificate $leafPem -PemKey $keyPem -Confirm:$false | Out-Null
|
||||
|
||||
Write-Host "==========================================================="
|
||||
Write-Host "SUCCESS: vCenter Machine SSL certificate updated." -ForegroundColor Green
|
||||
Write-Host "SUCCESS: vCenter Machine SSL certificate updated." ForegroundColor Green
|
||||
Write-Host "==========================================================="
|
||||
|
||||
Write-Log INFO "Certificate updated successfully."
|
||||
@@ -271,7 +271,7 @@ if ($needNewCert) {
|
||||
$null = $svc | Restart-VIApplianceService -Confirm:$false
|
||||
Write-Log INFO "vpxd restarted successfully."
|
||||
} catch {
|
||||
Write-Log WARN "vpxd restart failed: $($_.Exception.Message)" -ForegroundColor Orange
|
||||
Write-Log WARN "vpxd restart failed: $($_.Exception.Message)" Orange
|
||||
}
|
||||
|
||||
# ----------------------------
|
||||
@@ -285,7 +285,7 @@ if ($needNewCert) {
|
||||
$result = bash -c $sshCmd
|
||||
Write-Log INFO "Veeam rescan result: $result"
|
||||
} catch {
|
||||
Write-Log WARN "Veeam rescan failed: $($_.Exception.Message)" -ForegroundColor Orange
|
||||
Write-Log WARN "Veeam rescan failed: $($_.Exception.Message)" Orange
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user