Last active
December 3, 2020 22:55
-
-
Save mgreenegit/53cf9494759b71b2c8db to your computer and use it in GitHub Desktop.
Simple set of commands to maintain the WSMan trusted hosts list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-WSManTrust { | |
(Get-Item -Path WSMan:\localhost\Client\TrustedHosts | % Value).split(',') | |
} | |
function New-WSManTrust { | |
param( | |
[string]$hostname | |
) | |
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value $hostname -Concatenate -Force | |
} | |
function Remove-WSManTrust { | |
param( | |
[string]$hostname, | |
[switch]$all | |
) | |
if ($all) { | |
Clear-Item -Path WSMan:\localhost\Client\TrustedHosts -Force | |
} | |
else { | |
$list = Get-WSManTrust | |
$list = $list.replace($hostname+',','').replace($hostname,'') | |
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value $list -Force | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment