How to add more than one machine to the trusted hosts list using winrm How to add more than one machine to the trusted hosts list using winrm powershell powershell

How to add more than one machine to the trusted hosts list using winrm


I prefer to work with the PSDrive WSMan:\.

Get TrustedHosts

Get-Item WSMan:\localhost\Client\TrustedHosts

Set TrustedHosts

provide a single, comma-separated, string of computer names

Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'machineA,machineB'

or (dangerous) a wild-card

Set-Item WSMan:\localhost\Client\TrustedHosts -Value '*'

to append to the list, the -Concatenate parameter can be used

Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'machineC' -Concatenate


winrm set winrm/config/client '@{TrustedHosts="machineA,machineB"}'


The suggested answer by Loïc MICHEL blindly writes a new value to the TrustedHosts entry.
I believe, a better way would be to first query TrustedHosts.
As Jeffery Hicks posted in 2010, first query the TrustedHosts entry:

PS C:\> $current=(get-item WSMan:\localhost\Client\TrustedHosts).valuePS C:\> $current+=",testdsk23,alpha123"PS C:\> set-item WSMan:\localhost\Client\TrustedHosts –value $current