Plusieurs tips et outils concernant la configuration de WinRM sous Windows
Liste la configuration des listeners WinRM :
winrm e winrm/config/listener
Liste la configuration globale :
winrm get winrm/config
Set-WSManQuickConfig
Création du certificat autosigné (validité de 5 ans):
New-SelfSignedCertificate -DnsName "<nom-dns>" -CertStoreLocation Cert:\LocalMachine\My -KeyAlgorithm RSA -KeyLength 4096 -NotAfter (Get-Date).AddYears(5)
Pour de vieux serveurs windows, la directive
-NotAfter
n'existe pas, la validité doit être d'un an :New-SelfSignedCertificate -DnsName "<nom-dns>" -CertStoreLocation Cert:\LocalMachine\My
La création d'un certificat affiche un THUMBPRINT qu'il faut noter pour être configuré dans le listener WinRM, ex: 26616430677E4D9166025CB0EE357DB07D1E5B93
Créer le listener WinRM over HTTPS, sur le port 5986 :
winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="<nom-dns>"; CertificateThumbprint="<THUMBPRINT>"}'
Il faut avoir généré un nouveau certificat valide et être en possession de la THUMBPRINT correspondante
Set-WSManInstance -ResourceURI winrm/config/Listener -SelectorSet @{Address="*"; Transport="HTTPS"} -ValueSet @{Hostname="<nom-dns>"; CertificateThumbprint="<THUMBPRINT>"}
Afficher les informations de validité du certificat associé au listener WinRM HTTPS
Get-ChildItem -Path cert:\LocalMachine\My -Recurse | Where-Object { $_.Thumbprint -eq '<THUMBPRINT>' } | Select-Object *
On peut définir une ou plusieurs adresse IP :
Set-Item "wsman:\localhost\client\trustedhosts" -Value '10.0.0.1' -Force
Set-Item "wsman:\localhost\client\trustedhosts" -Value '10.0.0.1,10.0.0.2' -Force
Accepter les communications non chiffrées (WinRM sur le port 5985, over HTTP) :
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
Autoriser l'authentification Basic (login + password) :
winrm set winrm/config/service/auth '@{Basic="true"}'
Redémarre le service pour appliquer les modifications effectuées:
Get-Service -ComputerName localhost -Name WinRM | Restart-Service
Autoriser le traffic entrant sur les ports 5985 et 5986:
netsh advfirewall firewall add rule name=WINRM5985 dir=in action=allow protocol=TCP localport=5985
netsh advfirewall firewall add rule name=WINRM5986 dir=in action=allow protocol=TCP localport=5986