When you want to remotely manage a list of computer through WinRM (Windows Remote Management), you have to add computers to the TrustedHosts list. Otherwise, you may most likely encounter errors when communicating between the two sides. Using PowerShell, you can see what the current records are in the TrustedHosts file but also how to add new records depending on your scenario.
Below are the steps to add a server to the TrsutedHosts for WinRM client.
Set-Item WSMan:localhost\client\trustedhosts -value *
Note: You can add individual servers to the TrustHost via the following methods below.
Set-Item WSMan:localhost\client\trustedhosts -value ServerDC
In this way, you can add multiple servers to the TrustedHosts for WinRM.
Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'ServerDC,AnsibleClient'
To make this command run in an unattended mode (silently) without prompting you to acknowledge the security configuration, add the -Force to the command as shown below.
Set-Item WSMan:localhost\client\trustedhosts -value ServerDC -Force
You can also read the trusted host list with PowerShell, run the command below.
To add all domain computers to the TrustedHosts list, use the command as follow, Set-Item WSMan:\localhost\Client\TrustedHosts *.yourdomain.com
Set-Item WSMan:\localhost\Client\TrustedHosts *.techdirect.local
I hope you find these tips useful 😉