0

I first discovered that PowerShell is not working correctly when I open my VisualStudio 2019. The Package Manager Console was not working as you can see below:

`Cannot load Windows PowerShell snap-in Microsoft.PowerShell.Utility because of the following error: Could not load file or assembly 'Microsoft.PowerShell.Commands' or one of its dependencies.`

After I discovered this error i have done different things like: Done all updates available for Visual Studio 2019, all windows 10 updates, searched for the error everywhere but couldn´t find a similar question. Also tryed sfc /scannow.

I first tought it was only a Visual Studio error, but as I searched deeper, I found some suggestions like: Type write-host 'test' into Windows PowerShell, so I did. The error in Powershell.

Not just I can´t run simple commands like write-host 'test', I also can´t run Import-Module Microsoft.PowerShell.Utility to install the missing commands.

Anybody up with an idea that not includes to reinstall windows?

Output of $PSVersionTable:

Name Value
PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Operating System: Windows 10 Pro Version: 21H1

7
  • It seems that the autoload of Utility PS module fails when you use Write-Host. The Bad image format exception lets think that the core snapin is ok and can load module but fails with this one. Probable causes : Damaged module, bad PSModulePath, 32/64 bits path conflict. Can you give us the output of $env:PSModulePath ? And the output of get-module Microsoft.PowerShell.Utility | Format-Table ModuleType,Path -GroupBy Name -Wrap ? (if Format-Table fails, try get-module Microsoft.PowerShell.Utility | %{ $_.Path }) Commented Jun 14, 2021 at 8:01
  • @Zilog80 Output of $env:PSModulePath is : C:\Users\USERNAME\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules. get-module Microsoft.PowerShell.Utility | Format-Table ModuleType,Path -GroupBy Name -Wrap is not working and there is no Output for get-module Microsoft.PowerShell.Utility | %{ $_.Path } Commented Jun 14, 2021 at 8:14
  • Can you give us the cmd dir output of the folder C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\ ? Commented Jun 14, 2021 at 8:21
  • @Zilog80 there are two files: -a---- 07.12.2019 10:10 2473 Microsoft.PowerShell.Utility.psd1 -a---- 07.12.2019 10:10 30592 Microsoft.PowerShell.Utility.psm1 Commented Jun 14, 2021 at 11:10
  • Curious... You've the 3.1.0.0 version of the module, not the 3.0.0.0. Why did the importer look for a 3.0.0.0... if you try with import-module Microsoft.PowerShell.Utility -PassThru -RequiredVersion 3.1.0.0, what is the output ? Commented Jun 14, 2021 at 12:21

1 Answer 1

0

I still don´t know where the error came from, but I solved the problem by downloading the MediaCreationTool from Microsoft and created an ISO file. After that I startet die Setup.exe from the ISO. I "Reinstalled" Windows 10 with the option to keep my apps and documents. At first place I had an error 0xC1900101 - 0x2000c. I disconnected my dockingstation and tryed it again. Now it run successfully and I can use PowerShell again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.