header image

Clearing the trusted hosts list with Set-WSManInstance

Posted by: | May 22, 2014 | No Comment |

Sometimes you may just need to clear out all of the current values in the trusted hosts list and start again – especially in a lab environment where you may be experimenting.

function clear-trustedhost {
param (
[string]$computername = $env:COMPUTERNAME

if (Test-Connection -ComputerName $computername -Quiet -Count 1) {
  Set-WSManInstance -ResourceURI winrm/config/client -ComputerName $computername -ValueSet @{TrustedHosts = ""}
else {
  Write-Warning -Message "$computername is unreachable"


The trick is to use Set-WSManInstance to set the value of the TrustedHosts list to an empty string.  Don’t try and use $null  – it will fail

under: PowerShell Basics