mirror of
https://github.com/fscotto/infra.git
synced 2026-05-31 07:49:57 +00:00
Handle existing WinRM HTTPS listeners in bootstrap
This commit is contained in:
@@ -36,16 +36,31 @@ function Ensure-WinRMHttpsListener {
|
|||||||
|
|
||||||
$listener = Get-ChildItem -Path WSMan:\localhost\Listener |
|
$listener = Get-ChildItem -Path WSMan:\localhost\Listener |
|
||||||
Where-Object {
|
Where-Object {
|
||||||
$_.Keys -match 'Transport=HTTPS' -and $_.Keys -match "Hostname=$($env:COMPUTERNAME)"
|
$_.Keys -match 'Transport=HTTPS'
|
||||||
} |
|
} |
|
||||||
Select-Object -First 1
|
Select-Object -First 1
|
||||||
|
|
||||||
if ($null -eq $listener) {
|
if ($null -eq $listener) {
|
||||||
|
try {
|
||||||
New-WSManInstance -ResourceURI winrm/config/Listener `
|
New-WSManInstance -ResourceURI winrm/config/Listener `
|
||||||
-SelectorSet @{ Transport = 'HTTPS'; Address = '*' } `
|
-SelectorSet @{ Transport = 'HTTPS'; Address = '*' } `
|
||||||
-ValueSet @{ Hostname = $env:COMPUTERNAME; CertificateThumbprint = $CertificateThumbprint } | Out-Null
|
-ValueSet @{ Hostname = $env:COMPUTERNAME; CertificateThumbprint = $CertificateThumbprint } | Out-Null
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
$existingHttpsListener = Get-ChildItem -Path WSMan:\localhost\Listener |
|
||||||
|
Where-Object {
|
||||||
|
$_.Keys -match 'Transport=HTTPS'
|
||||||
|
} |
|
||||||
|
Select-Object -First 1
|
||||||
|
|
||||||
|
if ($null -ne $existingHttpsListener) {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
throw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user