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
UtilityPS module fails when you useWrite-Host. TheBad image formatexception 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 ofget-module Microsoft.PowerShell.Utility | Format-Table ModuleType,Path -GroupBy Name -Wrap? (ifFormat-Tablefails, tryget-module Microsoft.PowerShell.Utility | %{ $_.Path })$env:PSModulePathis :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 -Wrapis not working and there is no Output forget-module Microsoft.PowerShell.Utility | %{ $_.Path }diroutput of the folderC:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\?-a---- 07.12.2019 10:10 2473 Microsoft.PowerShell.Utility.psd1 -a---- 07.12.2019 10:10 30592 Microsoft.PowerShell.Utility.psm1import-module Microsoft.PowerShell.Utility -PassThru -RequiredVersion 3.1.0.0, what is the output ?