Skip to content

Instantly share code, notes, and snippets.

@mgreenegit
Last active December 3, 2020 22:55
Show Gist options
  • Save mgreenegit/53cf9494759b71b2c8db to your computer and use it in GitHub Desktop.
Save mgreenegit/53cf9494759b71b2c8db to your computer and use it in GitHub Desktop.
Simple set of commands to maintain the WSMan trusted hosts list
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