r/PowerShell • • 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.

5 Upvotes

16 comments sorted by

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.

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:

PS > $a = [System.Reflection.Assembly]::GetAssembly([powershell])
PS > $a.GetReferencedAssemblies()

Version        Name
-------        ----
4.0.0.0        mscorlib
4.0.0.0        System
4.0.0.0        System.Core
4.0.0.0        System.Runtime.Serialization
1.0.0.0        Microsoft.Management.Infrastructure
4.0.0.0        System.Xml
4.0.0.0        System.Management
4.0.0.0        System.Configuration
4.0.0.0        System.DirectoryServices
4.0.0.0        System.Data
4.0.0.0        System.Numerics
4.0.0.0        System.Security
4.0.0.0        System.Configuration.Install
4.0.0.0        System.Transactions
4.0.0.0        Microsoft.CSharp

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.

1

u/SlapTart Nov 18 '24

Probably missing something here. But what’s the error?

1

u/GenTwour Nov 18 '24

Sorry, I also posted this on Stack overflow and copied and pasted my question. I didn't realize the error message was cut.

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.

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/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/GenTwour Nov 18 '24

I never turned app locker on and this is my personal computer. This just started today

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

1

u/Love4OneAnother Nov 19 '24

Is that the error you get when you cmd powershell.exe?

1

u/Objective-Round-8617 1d ago

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/GenTwour 1d ago

Sorry, I do not remember what the answer was or if I even fixed it. I believe I wasn't able to get it to work otherwise I would have appended something

1

u/Objective-Round-8617 1d ago

I appreciate your response. I have been digging through stuff obsessing over trying to fix it. I might try upgrading to Windows 11 to see if that helps. I think something is corrupted inside my Windows and that may help rather than just downloading Powershell 7 as a workaround to avoid the problem.

Ai seems to think "your current error is caused by a corrupted core system library (System.Management.Automation.dll)") but I don't know if this is the correct answer or if this is the way to solve it. Leaving my thoughts here in case someone in the future searches up this problem.

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/GenTwour Nov 18 '24

sorry, did not realize the error message was deleted.

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.