The PowerShell console is a command-line interface (CLI) that allows you to interact with PowerShell. It is a text-based environment where you can type PowerShell commands and view their output.
When we launched powershell console on a Windows 10 device, It was a flashing powershell window for a second and then closing automatically. Powershell ISE is also not launching on the device.
A restart of the device was performed several times but this did not resolve the issue. You could try to launch powershell via windows command prompt but that could also result in below error:
Windows PowerShell terminated with the following error: Could not load file or assembly ‘System.Management.Automation, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The module was expected to contain an assembly manifest.
I could not find anything from Event viewer logs and tried to uninstall and re-install of powershell feature from the device but that also did not fix this issue. I will provide the solution which worked for me and also other troubleshooting steps / solutions which will help you to troubleshoot this issue.
If you are getting the same error then this could be due to the corrupted system file / module “System.Management.Automation.dll” which is located at “C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_126.96.36.199__31bf3856ad364e35” path.
The solution is to copy System.Management.Automation.dll file from a working and stable copy of Windows 10 or Windows 11. It does not matter if you are copying this file from a working Windows 11 device to a Windows 10 device or vice-versa. Only thing to note is to make sure to copy it from a Windows device where powershell is working fine.
You can easily copy this file from a working windows device but when you will try to paste it on the destination device, you may get below error message:
“The action can’t be completed because the folder or a file in it is open in another program. Close the folder or file and try again.“
As you can see from the above screenshot, this dll file is in use and therefore you cannot overwrite it. To fix this issue, I have performed below steps on command prompt launched as administrator.
Take Ownership of System.Management.Automation.dll file
takeown /f C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_188.8.131.52__31bf3856ad364e35\System.Management.Automation.dll
Grant Administrators full control on the System.Management.Automation.dll
icacls "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_184.108.40.206__31bf3856ad364e35\System.Management.Automation.dll" /GRANT ADMINISTRATORS:F
Now, next step is to copy the file System.Management.Automation.dll from working device and the paste it in a temporary location first on the faulty device. I have copied it at C:\Temp location and from C:\Temp location I am copying this file to C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_220.127.116.11__31bf3856ad364e35\System.Management.Automation.dll” location.
Copy good copy of System.Management.Automation.dll to c:\windows\….
copy C:\Temp\System.Management.Automation.dll "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_18.104.22.168__31bf3856ad364e35\System.Management.Automation.dll"
You can restart your device and then launch powershell console. This time it should launch successfully.
You can start powershell from windows command prompt as well. I have tested it and found that its also working file after replacing the dll file.
There are other solutions which you could try as well, It could be that you are not getting that specific error message but experiencing the same type of issue where powershell console may be crashing.
Uninstall and Re-Install Powershell
You can try to uninstall and re-install powershell feature which could replace the corrupted files and may fix the issue. To Uninstall Powershell feature on a windows device, you can either user command prompt or use GUI as well. Let’s check the steps:
Disable Powershell feature
Dism /online /Disable-Feature /FeatureName:"MicrosoftWindowsPowerShellV2Root"
Enable Powershell feature
Dism /online /Enable-Feature /FeatureName:"MicrosoftWindowsPowerShellV2Root"
To uninstall powershell feature using GUI, you can use below steps:
- Press Windows key + R to open Run box > type appwiz.cpl and press Enter.
- Click on Turn Windows features on or off link on the left hand side.
- Scroll down on the list to find Windows Powershell 2.0 and Uncheck the selection.
- Press Ok to Uninstall
Run System file checker tool
System File Checker can scan Windows and restore corrupted system files. First we will run Deployment Image Servicing and Management (DISM) tool and then SFC.exe System File checker tool.
/RestoreHealth argument to repair the image.
DISM.exe /Online /Cleanup-image /Restorehealth
You may get below error message while trying to run this command
The source files could not be found.
Use the “Source” option to specify the location of the files that are required to restore the feature. For more information on specifying a source location, see https://go.microsoft.com/fwlink/?LinkId=243077.
This could be because of no internet connection or firewall issue. You could try an offline restore method by copying Windows folder from a working Windows computer to faulty computer and providing it as a source to restore the files.
DISM Offline Windows System files repair
DISM.exe /Online /Cleanup-Image /RestoreHealth /Source:C:\RepairSource\Windows /LimitAccess
LimitAccess tells DISM to not check Windows Update or Windows Server Update Services for the capability source files.
After completing a Windows repair using DISM Commad. Run System file checker tool to scan all protected system files, and replace corrupted files with a cached copy that is located in a compressed folder at C:\Windows\System32\dllcache.
System file checker tool
In this blog post, we have seen how to fix Powershell launch errors which could be fixed easily by replacing corrupted dll file. You can also run system cheker tool to repair corrupted system files. If the problem cannot be resolved even after taking all the steps listed in this blog post, you can take back up of data from your device and Reset the device which will replace / fix all corrupted files.