TransWikia.com

What would be causing "PowerShell.exe" to hang upon opening on multiple systems and/or how can I troubleshoot it?

Server Fault Asked on November 7, 2021

What would be causing “PowerShell.exe” to hang upon opening on multiple systems?

I’ve waited for over 60 minutes, but it never fully starts. All it does is show the blue shell window with the typical PowerShell startup output of:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Then it just hangs. My suspicion is that it’s not actually a PowerShell problem, but something else such as .NET, or McAfee that is causing it, but I just don’t know.

I’ve tried starting PowerShell everyway I know how, but no matter what I try, the only fix I’ve found so far is to reboot the system. A reboot might be an acceptable fix if it weren’t on servers, and the issue never came back, however it eventually returns after a while (perhaps several weeks later). I’ve seen this on numerous servers. More than 15, but I’m not sure exactly how many. I’d guess at least half of our servers, so at least 40 servers or so. It has happened on both Windows Server 2016 and 2019, but I do not remember seeing it happen on any of our 2012 R2 servers.

This is causing a problem with our “morning checks” script that tries to check the last Windows Server backup on multiple servers in a foreach loop using “New-PSSession” like this:

$rsession = New-PSSession -ComputerName $Server -ErrorAction Stop; 
Invoke-Command -Session $rsession -ScriptBlock {...}

The script block is very small/simple (only a couple of ‘Get-WBJob’ commands). Once the script reaches the first server experiencing this problem, it hangs indefinitely (again, I’ve waited for over 60 minutes). If I reboot that remote system, it continues until it reaches another remote system experiencing this problem. I experience this same result (hanging) if instead of the script, I just try something like this:

Enter-PSSession -ComputerName Server2

On a system experiencing the problem, I tried starting the powershell executable from cmd in the following ways with no difference:

start PowerShell.exe -NoProfile
start PowerShell.exe -NoProfile -ExecutionPolicy Unrestricted
start PowerShell.exe -NoProfile -ExecutionPolicy Restricted

But it didn’t matter. However, I was able to get PowerShell to run using the following option:

start PowerShell.exe -version 2.0

Version 2.0 is not enabled on many of our servers though and I don’t think that helps remote commands, but it’s a clue of what might be happening. The thought went through my mind that it could be a failed or pending Windows patch that’s causing PowerShell 5.1 to not be able to load. That might explain the problem returning every few weeks or so. I ran the two commands below, but they made no difference:

sfc /scannow
dism /online /cleanup-image /restorehealth

I’ve watched the Application and System event logs while I attempt to launch PowerShell, but have seen no events occur in those logs at that time. However, under Applications and Services Logs –> Microsoft –> Windows –> PowerShell –> Operational, I see two events each time:

  1. Event ID: 40961 “PowerShell console is starting up”

  2. Event ID 53504 “Windows PowerShell has started an IPC listening thread on process: 173724 in AppDomain: DefaultAppDomain.” (the process number changes each time of course)

I’m wondering if maybe SysInternals Procmon will help identify the root cause, but I’m not very familiar with the tool, and am looking for suggestions on that or a better troubleshooting method. The problem is not happening right at this moment, so I can’t troubleshoot it until it starts again, but I fear it will return soon and plague me until I solve the root cause.

One Answer

I was having this same issue, unsure of exactly what the problem was but I managed to fix it by disabling Powershell 2.0. I ran windows key + R, then optionalfeatures.exe, disabled Windows Powershell 2.0 and restarted my PC. I then noticed there was still powershell installed on my PC and ran that and it is now working. I think there must have been some issue with 2 different versions of Powershell being installed at the same time.

Answered by Connorcy on November 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP