Powershell broke - basic commands not working, not loading modules from common folders

Mikhail Ladanov 1 Reputation point
2021-01-05T04:12:12.313+00:00

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?

Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-01-05T06:52:34.927+00:00

    Hi,

    Check if $env:PSModulePath contains C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules. If not, add them to the system variable "PSModulePath" in Environment Variables in System Properties window.

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.