Add hpz440 host configuration and SSH setup for Windows; update Prometheus targets and variables
This commit is contained in:
@@ -165,11 +165,20 @@ Function New-LegacySelfSignedCert {
|
||||
$certdata = $enrollment.CreateRequest(0)
|
||||
$enrollment.InstallResponse(2, $certdata, 0, "")
|
||||
|
||||
# extract/return the thumbprint from the generated cert
|
||||
$parsed_cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
|
||||
$parsed_cert.Import([System.Text.Encoding]::UTF8.GetBytes($certdata))
|
||||
|
||||
return $parsed_cert.Thumbprint
|
||||
try {
|
||||
# Try to decode as base64 (most likely) then construct the cert from raw bytes.
|
||||
$raw = $null
|
||||
try {
|
||||
$raw = [Convert]::FromBase64String($certdata)
|
||||
} catch {
|
||||
# Fallback to UTF8 bytes if it's not base64
|
||||
$raw = [System.Text.Encoding]::UTF8.GetBytes($certdata)
|
||||
}
|
||||
$parsed_cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList (, $raw)
|
||||
return $parsed_cert.Thumbprint
|
||||
} catch {
|
||||
Throw "Failed to construct X509Certificate2 from generated data: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
Function Enable-GlobalHttpFirewallAccess {
|
||||
@@ -327,7 +336,9 @@ If (!($listeners | Where-Object { $_.Keys -like "TRANSPORT=HTTPS" })) {
|
||||
}
|
||||
|
||||
Write-Verbose "Enabling SSL listener."
|
||||
New-WSManInstance -ResourceURI 'winrm/config/Listener' -SelectorSet $selectorset -ValueSet $valueset
|
||||
# Fallback to winrm.exe create which is more compatible across WinRM versions
|
||||
$body = "@{Hostname=`"$SubjectName`";CertificateThumbprint=`"$thumbprint`"}"
|
||||
& winrm create 'winrm/config/Listener?Address=*+Transport=HTTPS' $body
|
||||
Write-ProgressLog "Enabled SSL listener."
|
||||
}
|
||||
Else {
|
||||
@@ -353,7 +364,8 @@ Else {
|
||||
Remove-WSManInstance -ResourceURI 'winrm/config/Listener' -SelectorSet $selectorset
|
||||
|
||||
# Add new Listener with new SSL cert
|
||||
New-WSManInstance -ResourceURI 'winrm/config/Listener' -SelectorSet $selectorset -ValueSet $valueset
|
||||
$body = "@{Hostname=`"$SubjectName`";CertificateThumbprint=`"$thumbprint`"}"
|
||||
& winrm create 'winrm/config/Listener?Address=*+Transport=HTTPS' $body
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user