header image

Trusted hosts

Posted by: | December 28, 2019 Comments Off on Trusted hosts |

You can use trusted hosts in WSMAN based PowerShell remoting to authenticate computers where Kerberos isn’t available.

The WSMAN configuration is available through the WSMAN PowerShell drive or you can use the WSMANInstance cmdlets – available in Windows PowerShell v5.1, PowerShell 6.2 (Seem to have come back in at PowerShell v6.1) or PowerShell v7

function get-trustedhost {
[CmdletBinding()]
param (
[string]$computername = $env:COMPUTERNAME
)

if (Test-Connection -ComputerName $computername -Quiet -Count 1) {
Get-WSManInstance -ResourceURI winrm/config/client -ComputerName $computername |
Select-Object -ExpandProperty TrustedHosts
}
else {
Write-Warning -Message “$computername is unreachable”
}

}

 

The only non-obvious piece of code is the resource URI which you can work out from the examples in the help file. By contrast using the WSMAN drive you need to access

Get-ChildItem -Path WSMan:\localhost\Client\

under: PowerShell

Comments are closed.

Categories