Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

PowerShell remoting fails with 0x80090322 or asks for TrustedHosts: fix the SPN or use HTTPS, not a wildcard

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

An administrator runs Enter-PSSession to a domain server and gets one of two errors. The first names a security error and a code:

Enter-PSSession : Connecting to remote server <FQDN> failed with the following error message : WinRM cannot process the request. The following error with error code 0x80090322 occurred while using Kerberos authentication: An unknown security error occurred.

The second tells them to change a client setting:

ERROR: The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting.

Both come from how the client authenticates to the server. A common response to the second is to add every host to TrustedHosts with a wildcard. Microsoft's security guidance explains that this does not make the connection trusted: it only suppresses the error raised because the server's identity cannot be checked.

What you see

Why it happens

0x80090322: the HTTP SPN belongs to someone else. Microsoft says PowerShell connects using a Kerberos service principal name (SPN) of the form HTTP/<FQDN>. The error occurs when that SPN is already registered to another service account in the forest, or was registered by hand for a web service on the same computer. It follows that the client is given a ticket for the other account, which the server cannot use.

TrustedHosts message: Kerberos is not possible. Microsoft's remoting security page says Kerberos is the default when a client connects to a domain server by its computer name. Kerberos proves both the user and the server. When the client connects by IP address, or to a workgroup server, Kerberos is not possible and PowerShell falls back to NTLM (Microsoft Learn, Security Considerations for PowerShell Remoting using WinRM). NTLM proves the user but not the server. For that reason, Microsoft says NTLM-based remoting is disabled by default: you allow it either with SSL on the target server or with the TrustedHosts setting on the client.

How to prove the cause

1. Note how you connected. If you used an IP address or a workgroup computer, the TrustedHosts message is expected; go to the TrustedHosts fixes. If you used the server's full domain name and got 0x80090322, check the SPN.

2. Find who owns the HTTP SPN. Microsoft's first step, run from a domain computer:

setspn -q http/<FQDN>

If it shows the SPN registered to a service account rather than the server's own computer account, that is the cause Microsoft describes.

3. See what the client already trusts. On the client:

Get-Item WSMan:\localhost\Client\TrustedHosts

Microsoft says only administrators can change the list, and the value affects all users of the computer.

4. Check the server's listeners. On the server:

winrm enumerate winrm/config/listener

This shows whether an HTTPS listener exists and which certificate thumbprint it uses (Microsoft Learn, How to configure WINRM for HTTPS).

The fix

For 0x80090322

Microsoft gives three options.

Option 1: remove the SPN from the service account if it is no longer needed. It follows that you should first check what uses that account, because a web application may depend on that SPN for its own Kerberos sign-in.

Option 2: give WinRM its own SPN with the port number, registered on the server's computer account, then ask for the port in the SPN when connecting. Microsoft's example, for a server named Mem1:

Setspn -s HTTP/Mem1:5985 Mem1
Setspn -s HTTP/Mem1.contoso.com:5985 Mem1
Enter-PSSession -Computername mem1.contoso.com -SessionOption (New-PSSessionOption -IncludePortInSPN)

Option 3: make the client ask for a WSMAN SPN instead of HTTP. On the client computer, Microsoft's registry change. It changes the client's registry and affects every WinRM connection that client makes, so back up the key first:

reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Client /v spn_prefix /t REG_SZ /d "WSMAN" /f

Then add WSMAN SPNs to the server's computer account, using Microsoft's example:

Setspn -s WSMAN/mem1 mem1
Setspn -s WSMAN/mem1.contoso.com mem1

For the TrustedHosts message

Connect by name where you can. It follows from Microsoft's security page that connecting to a domain server by its computer name keeps Kerberos, which proves the server's identity and needs no TrustedHosts entry.

Where you must use NTLM, set up HTTPS on the target. Microsoft's security page says an SSL certificate from an authority the client trusts lets NTLM connections prove the server's identity as well. Microsoft's HTTPS page says the server needs a local computer Server Authentication certificate whose name matches the host name, not expired, revoked or self-signed. Once it is installed, Microsoft's command creates the listener:

winrm quickconfig -transport:https

Microsoft also says remote commands that use NTLM must use the Credential parameter, even when connecting as the current user.

If you use TrustedHosts, list specific hosts, not *. Microsoft's example sets one computer:

$server = 'Server01.Domain01.Fabrikam.com'
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $server

That command replaces the whole list. To add a host to an existing list, Microsoft's form keeps the current value:

$newServer = 'Server01.Domain01.Fabrikam.com'
$curValue = (Get-Item WSMan:\localhost\Client\TrustedHosts).Value
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "$curValue, $newServer"

Microsoft's security page explains what this does: TrustedHosts is not a statement that those hosts are trustworthy. It is the list of hosts for which you choose to suppress the error raised because the server's identity cannot be checked. It follows that * suppresses that error for every host the computer connects to, for every user of that computer.

How to confirm the fix

  • Enter-PSSession by full domain name connects without 0x80090322.
  • setspn -q http/<FQDN> (or the WSMAN SPN, if you chose option 3) shows the SPN on one account only.
  • For HTTPS, winrm enumerate winrm/config/listener shows an HTTPS listener, and its thumbprint matches the certificate you installed. Microsoft says to check this when there is more than one server certificate.
  • Get-Item WSMan:\localhost\Client\TrustedHosts shows only the hosts you meant to add.

What to watch afterwards

  • New web applications on servers you manage remotely. It follows from the 0x80090322 cause that registering an HTTP/<FQDN> SPN for a web application's account can break remoting to that server again.
  • Certificate expiry. An HTTPS listener depends on a certificate that is not expired. Microsoft's HTTPS page lists certificate validity dates as the first thing to check when the listener cannot be created.
  • TrustedHosts entries added during an emergency. Check the list from time to time and remove entries that are no longer needed.
  • Network profile. Microsoft's security page says the default firewall rule on public networks allows remoting only from the same subnet.

Risks and limits

  • Removing an SPN can break the service that owns it. Microsoft's option 1 says to check whether the SPN is still needed first.
  • The registry change in option 3 is a client setting. It follows that it must be applied on every client that connects, not on the server.
  • Ports. On Windows 7 and later, WinRM uses 5985 for HTTP and 5986 for HTTPS. Microsoft's HTTPS page says ports 80 and 443 were the defaults on earlier Windows versions, which is why some older pages, including about_Remote_Troubleshooting, still mention port 80. This article uses 5985 and 5986, as in the 0x80090322 page's commands.
  • What HTTP and HTTPS each encrypt. Microsoft's security page says that over HTTP, WinRM uses "the message-level encryption negotiated by the initial authentication protocol". Kerberos and NTLM therefore encrypt the traffic, but "Basic authentication provides no encryption." HTTPS adds TLS on top. When the HTTPS page says plain winrm quickconfig data "won't be encrypted", it means there is no TLS layer. For NTLM connections, the main gain from HTTPS is proving the server's identity, and it also protects Basic authentication.
  • After HTTPS is set up, the client must ask for it: add -UseSSL to Enter-PSSession or Invoke-Command (it uses port 5986 by default). Without it, the connection still goes over HTTP, even if you name port 5986 (Microsoft Learn, Enter-PSSession).
  • Changing WSMan: settings requires PowerShell run as administrator, according to Microsoft.

Sources

Next step

0x80090322 means the server's HTTP SPN belongs to another account; the TrustedHosts message means Kerberos could not be used at all. Fix the SPN or use HTTPS, and keep TrustedHosts to named hosts. NetLeverage has looked after business servers since 2002. If remoting still fails, talk to us through managed support with the exact error, how you connected (name or IP address) and the setspn -q output.