How to fix "The WS-Management identification operation is only available on remote sessions."
Error Description
The error "The WS-Management identification operation is only available on remote sessions" occurs in Windows (typically when using PowerShell or WinRM commands like Test-WSMan or Connect-WSMan) when you attempt to run a WS-Management operation targeting the local machine (localhost or 127.0.0.1) using parameters or mechanisms designed strictly for remote endpoints. WinRM actively prevents certain identity verification loops on the local host to maintain security boundaries and prevent loopback authentication issues.
Step-by-Step Fixes
Method 1: Remove the Target Parameter for Local Testing
If you are troubleshooting WinRM on your current machine, running the command with explicit local loopback addresses triggers this error.
- Open PowerShell as an Administrator.
- Instead of running:
Test-WSMan -ComputerName localhost - Run the command without the computer name parameter to test the local WinRM service:
Test-WSMan
Method 2: Enable Remote Management Local Loopback (DisableLoopbackCheck)
If your application or script strictly requires connecting to localhost via an explicit remote-style session call, you must modify the Windows Registry to allow local loopback authentication.
- Press the Windows Key + R, type
regedit, and press Enter to open the Registry Editor. - Navigate to the following path:
HKEY LOCAL MACHINE\SYSTEM\CurrentControlSet\Control\Lsa - Right-click on the Lsa folder, select New, and then click DWORD (32-bit) Value.
- Name the new value
DisableLoopbackCheck. - Double-click
DisableLoopbackCheck, change its Value data to1, and keep the Base as Hexadecimal. - Click OK and restart your computer for changes to take effect.
Method 3: Configure WinRM Trusted Hosts
Sometimes the security policy restricts WS-Management traffic even internally. Forcing WinRM to trust all hosts (or your specific local configuration) bypasses strict identification blocks.
- Right-click the Start menu and select Terminal (Admin) or PowerShell (Admin).
- Run the following command to allow loopback and remote authentication alignment:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force - Restart the WinRM service to apply the configuration:
Restart-Service WinRM
Method 4: Use New-PSSession for Local Scenarios
If you must simulate a remote session context locally for a script, establish a formal PowerShell Session rather than a direct connection invocation.
- Open your script or PowerShell console.
- Initialize the connection as a session block like this:
\$session = New-PSSession -ComputerName "localhost" Invoke-Command -Session \$session -ScriptBlock { Get-Process } Remove-PSSession \$session
There may be some errors. Learn Microsoft