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

Mikhail Ladanov 1 Reputation point

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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,432 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 32,236 Reputation points Microsoft Vendor


    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.