At some point my Powershell broke. Standard commands like 'Write-Host' stopped working.
I was using VS Code on Windows 10 and using PowerShell 5.1
Checked all the environmental variables, everything looks fine.
Couldn't fix it and got a new machine.
Did literally the following:
- Installed VS Code
- Turned on Powershell extension in VS Code
- It prompted something about Package Manager needing an update or it will not work properly
- Asked me to install NuGet to get the Package Manager
- After that PowerShell 5.1 stopped working again.
- Somewhere in between installed Git
After that PowerShell stopped working.
Exactly the same symptoms: Modules not autoloading, fresh instance of powershell does this:
PS C:\WINDOWS\system32> Write-Host
Write-Host : The term 'Write-Host' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ Write-Host
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Did some more troubleshooting. Created a local user and repeated all the steps:
- Created a local user
- Installed VS Code
- Installed Powershell Extension within VS Code
- It asked to update PackageManagement
- Said it needed NuGet to update PackageManagement, installed
- Installed Git
Everything is working.
Some more troubleshooting showed that my main user does not look into folders C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules when looking for a cmdlet. It only looks into C:\Users\myMainUser\Documents\WindowsPowerShell\Modules. So I either have to do Import-Module -Name Microsoft.PowerShell.Management and so on, or copy all the modules into C:\Users\myMainUser\Documents\WindowsPowerShell\Modules.
My temporary user apparently functions normally.
Any ideas?