Learn How to Easily Troubleshoot PowerShell Remoting

Doctor Scripto

Summary: Microsoft Scripting Guy, Ed Wilson, shows you how to easily troubleshoot Windows PowerShell remoting.

Hey, Scripting Guy! Question Hey, Scripting Guy! I have a problem. I am running Windows 8 on my desktop, and I have upgraded our Hyper-V servers to Windows Server 2012. For those computers, I can easily use Windows PowerShell remoting and I have not seen a single problem. But when I attempt to connect to our servers running Windows Server 2008 R2, and even the Windows Server 2008 servers, then it seems to be hit or miss. I need an easy way to troubleshoot this without doing a lot of special logging and going all extreme. Can you help?

—KG

Hey, Scripting Guy! Answer Hello KG,

Microsoft Scripting Guy, Ed Wilson, is here. Well, today I am all in a dither (or a tither, not sure which). I just got a picture of Dr. Scripto through the email—no, no one has kidnapped him (á la Who’s Harry Crumb), no, the picture is from my friend Kurt Hudson, who is a senior technical writer on the Information Experience team. You see, he and I were in meetings together a few weeks ago when I was in Redmond, and he mentioned his hobby—welding. I suggested he might try to weld a figure of Dr. Scripto—he not only accepted the challenge, as you can see in the image here, he excelled.

Image of Dr. Scripto sculpture

Well, KG, as it turns out, I was reviewing a chapter from my Windows PowerShell 3.0 First Steps book by Microsoft Press, and it seems that is the best way for me to answer your question—without the need to reinvent the wheel.

So, here goes …

Troubleshooting Windows PowerShell Remoting

The first tool to use to see if Windows PowerShell remoting is working (or not) is the Test-WSMan cmdlet. Use it first on the local computer (no parameters are required). The command and its associated output are shown here.

PS C:\> Test-WSMan

wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 3.0

To test a remote computer, specify the –ComputerName parameter. This following command runs against a Windows Server 2012 domain controller named DC3.

PS C:\> Test-WSMan -ComputerName dc3

wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 3.0

But the Test-WSMan cmdlet also works against a computer running Windows PowerShell 2.0. The following command runs against a Windows Server 2008 domain controller named DC1.

PS C:\> Test-WSMan -ComputerName dc1

wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 2.0

To examine a specific Windows PowerShell session, use the Get-PSSession cmdlet. The easiest way to do this is to pipe the variable containing the Windows PowerShell session to the Get-PSSession cmdlet. The key items to pay attention to are the computer name, the state of the session, and the availability of the session. This technique is shown here.

PS C:\> $ps | Get-PSSession

 Id Name            ComputerName    State         ConfigurationName     Availability
 — —-            ————    —–         —————–     ————
  3 Session3        ex1             Opened        Microsoft.PowerShell     Available
  4 Session4        dc3             Opened        Microsoft.PowerShell     Available

To focus on a specific session, reference the session by either ID or by Name. Send the returned session object over the pipeline to the Format-List cmdlet and select all of the properties. This technique is shown here (using fl as an alias for the Format-List cmdlet).

PS C:\> Get-PSSession -Name Session4 | fl *

State                  : Opened
IdleTimeout            : 7200000
OutputBufferingMode    : None
ComputerName           : dc3
ConfigurationName      : Microsoft.PowerShell
InstanceId             : c15cc80d-64f0-4096-a010-0211f0188aec
Id                     : 4
Name                   : Session4
Availability           : Available
ApplicationPrivateData : {PSVersionTable}
Runspace               : System.Management.Automation.RemoteRunspace

You can remove a remote Windows PowerShell session by piping the results of Get-PSSession to the Remove-PSSession cmdlet. This technique is shown here.

Get-PSSession -Name Session4 | Remove-PSSession

You can also remove a PS session directly by specifying the name to the Remove-PSSession cmdlet. This technique is shown here.

Remove-PSSession -Name session3

KG, that is all there is to using the built-in Windows PowerShell cmdlets to troubleshooting remoting. Join me tomorrow for the exciting conclusion to Microsoft MVP and honorary Scripting Guy Richard Siddaway’s workflow series.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

0 comments

Discussion is closed.

Feedback usabilla icon