Clearing the trusted hosts list

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

This entry was posted in Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s