r/PowerShell • u/GenTwour • Nov 18 '24
Powershell won't open and I cannot figure out why.
Whenever I try to open powershell, it instantly closes. When I open a new terminal in VScode, I get this error:
Windows PowerShell terminated with the following error:
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an assembly manifest.
Any help would be appreciated. I have tried repairing my windows installation with sfc /scannow and DISM /Online /Cleanup-Image /RestoreHealth. I don't really know much about powershell.
I couldn't get the defualt powershell that comes with windows to work. However, I installed powershell 7 using this guide (https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4) and now it is working.
2
u/purplemonkeymad Nov 18 '24
Sounds like your GAC might be missing some stuff? According to my powershell process it needs the following dependencies:
They should all have a folder in the GAC: C:\Windows\Microsoft.NET\assembly\GAC_MSIL or GAC_64
I would check if any are missing, or if their signature is not valid/present.
6
u/-Invalid_Selection- Nov 18 '24
oh, well that's not good. You can try installing powershell 5.1 or 7, otherwise your windows install is probably corrupted in some way and you need to reload it.
1
u/SlapTart Nov 18 '24
Probably missing something here. But what’s the error?
1
u/Red_5r Nov 18 '24
Maybe a shot in the dark here, but is AppLocker turned on? I’ve had issues where PS would do exactly what you’re seeing, and it was AppLocker being too restrictive. If not that, maybe some other security software or policy is affecting you.
1
u/Love4OneAnother Nov 19 '24
Is that the error you get when you cmd powershell.exe?
1
u/Objective-Round-8617 Oct 05 '26
Hi I am having the exact same error message in the future. Have also tried the same thing. Were you ever able to fix it? I also don't know much about Powershell and have tried the same commands but haven't tried downloading Powershell 7 yet
1
u/ennova2005 Nov 18 '24
Cant see your error image. First open a CMD window and type powershell.exe and then see what i reports.
I suspect you trying to open the PS EXE by right clicking/run. Since the shell has nothing to do, it exits right away.
1
u/[deleted] Nov 18 '24
Something got messed up there. That assembly it’s trying to import is a reference assembly- that is, it has all the information you need to develop something for powershell but it doesn’t have any executable code in it.
The first thing to do is to run sfc /scannow. See if that reports any errors.
Then have a look your path variable. That reference assembly folder in program files? It MUST NOT be in it.
If those don’t help, search for system.management.automation.dll and look at its versions and sizes.
You are looking for something with 5.1. Something- anything greater would be ps core; anything less would either suggest an outdated system or a reference assembly (those commonly use 3.0.0.0 for their file version).
Then post any findings here along with their paths in the filesystem. If you feel safe enough, you can RENAME rather than delete any such dll that’s older than 5.1; but be aware this might mess with powershell development tools or development extensions.
1
u/[deleted] Nov 19 '24
The assembly file System.Management.Automation.dll is usually located in:
Windows PowerShell 5.1: C:\Windows\System32\WindowsPowerShell\v1.0\
Delete the DLL file and then repair windows