问题原文
原帖链接 · Jared · CC BY-SA 3.0
I am looking to enable WinRM HTTPS listeners on all of our servers for secure communication when using CredSSP between servers to get around the double-hop issue.
Setting this up is fine, we have CN-appropriate certificates from an internal CA so the initial setup of the listeners is fine and works great. The only thing is these certificates are only valid for 1 year, so once they expire we'll need to re-configure the listeners on each server, as the auto-enrollment of the server certificates does not modify the cert thumbprint in the WinRM configuration.
Has anyone encountered a nice solution to this issue?
社区高分解答
原帖链接 · Ryan Fisher · CC BY-SA 4.0
I have recently put together a short script in order to do the same thing you are trying to accomplish, here are the relevant parts. Be aware that you will get an error at the end as the Invoke-Command is going to reset the WinRM service while you are waiting for the result of the Restart-Service command...
$yourCred = Get-Credential domain\account
$yourServer = "your.server.fqdn"
$LatestThumb = Invoke-Command -ComputerName $yourServer `
-Credential $yourCred `
-ScriptBlock {
Get-ChildItem -Path Cert:\LocalMachine\My |
Where-Object {$_.subject -match "CN=$yourServer"} |
Sort-Object -Property NotAfter |
Select-Object -Last 1 -ExpandProperty Thumbprint
}
Set-WSManInstance -ResourceURI winrm/config/Listener `
-SelectorSet @{Address="*";Transport="HTTPS"} `
-ComputerName $yourServer `
-Credential $yourCred `
-ValueSet @{CertificateThumbprint=$LatestThumb}
Invoke-Command -ComputerName $yourServer `
-Credential $yourCred `
-ScriptBlock { Restart-Service -Force -Name WinRM }
This is running against Server 2008 R2, with Posh v3. I would bet it works against Server 2012, but it may need some work for v2.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
