When I was going to run the script for cleaning up certificates on all servers for a customer, I ran into some issues connecting to many of the servers. Turns out there were only a few servers on the TrustedHosts list. Obviously, this will not for good remote management make. I should stop trying to sound fancy, but I digress.

This will be a quick one, as it's a pretty straight forward process. We start by getting the DNS hostname from all of the servers in Active Directory. You could use searchbase to define a Organization Unit but in this case we just want to grab all the servers.

Then, for each server in out list of servers, we add the hostname to the TrustedHosts list. We do this by using Set-Item with the -Concatenate switch.

$servers = (Get-AdComputer -Filter *).DNSHostName
foreach ($server in $servers) {
    Set-Item WSMan:\localhost\Client\TrustedHosts -Value $server -Concatenate