PowerShell commands no longer recognized

8,756

PowerShell commands no longer work

The $env:psmodulepath seems to be correct:

$env:psmodulepath
C:\Users\myuserid\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\;C:\windows\system32\WindowsPowerShell\v1.0\Modules";C:\Program Files\WindowsPowerShell\Modules

You have a " (double quote) in the middle of your $env:psmodulepath which isn't there on my installation:

PS F:\test> $env:psmodulepath
C:\Users\DavidPostill\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules

You can remove the double quote by setting $env:psmodulepath explicitly yourself.

Share:
8,756

Related videos on Youtube

Eric
Author by

Eric

Updated on September 18, 2022

Comments

  • Eric
    Eric over 1 year

    I installed a package on my Win7 x64 computer using Chocolately. As part of the installation, it wanted to upgrade PowerShell to 5.0. Since this happened basic PowerShell commands no longer work. I've searched around on the web and haven't really found anything useful. I'm really stumped on what to do.

    Here's an example:

    PS>Get-Location
    Get-Location : The term 'Get-Location' 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
    + Get-Location
    + ~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Get-Location:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
    PS>
    

    I can see that it's resolving aliases for my commands, for instance:

    PS>dir
    dir : The term 'Get-ChildItem' 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
    + dir
    + ~~~
        + CategoryInfo          : ObjectNotFound: (Get-ChildItem:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
    PS>
    

    I have another alias set in my $profile and I can see that it is getting recognized. If I type xx my PowerShell instance will close:

    function global:xx
    {   
        exit
    }
    

    The $env:psmodulepath seems to be correct:

    PS>$env:psmodulepath
    C:\Users\myuserid\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\;C:\w
    indows\system32\WindowsPowerShell\v1.0\Modules";C:\Program Files\WindowsPowerShell\Modules
    PS>cmd
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\windows\system32>dir c:\windows\system32\WindowsPowerShell\v1.0\Modules
     Volume in drive C is OS
     Volume Serial Number is 605E-A0FF
    
     Directory of c:\windows\system32\WindowsPowerShell\v1.0\Modules
    
    06/22/2016  11:41 PM    <DIR>          .
    06/22/2016  11:41 PM    <DIR>          ..
    05/20/2016  02:24 PM    <DIR>          ApplicationServer
    06/22/2016  11:41 PM    <DIR>          CimCmdlets
    06/22/2016  11:41 PM    <DIR>          ISE
    06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Archive
    06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Diagnostics
    06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Host
    06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Management
    06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.ODataUtils
    06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Security
    06/22/2016  11:41 PM    <DIR>          Microsoft.PowerShell.Utility
    06/22/2016  11:41 PM    <DIR>          Microsoft.WSMan.Management
    06/22/2016  11:41 PM    <DIR>          NetworkSwitchManager
    06/22/2016  11:41 PM    <DIR>          PSDesiredStateConfiguration
    06/22/2016  11:41 PM    <DIR>          PSDiagnostics
    06/22/2016  11:41 PM    <DIR>          PSScheduledJob
    06/22/2016  11:41 PM    <DIR>          PSWorkflow
    06/22/2016  11:41 PM    <DIR>          PSWorkflowUtility
    11/21/2010  02:24 AM    <DIR>          TroubleshootingPack
    10/31/2014  04:26 PM    <DIR>          WebAdministration
                   0 File(s)              0 bytes
                  21 Dir(s)   2,301,882,368 bytes free
    
    C:\windows\system32>
    
    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 almost 8 years
      To avoid us suggesting things you already tried, please edit your question and include what it is you've tried already.
    • Peter Hahndorf
      Peter Hahndorf almost 8 years
      Do you have C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules in $env:psmodulepath? Seems to me the installation killed your PsModulePath environment variable
    • Eric
      Eric almost 8 years
      Yes, I see the following PS>$env:psmodulepath C:\Users\myuserid\Documents\WindowsPowerShell\Modules;C:\Pro‌​gram Files (x86)\PowerShell Community Extensions\Pscx3\;C:\w indows\system32\WindowsPowerShell\v1.0\Modules";C:\Program Files\WindowsPowerShell\Modules PS>
    • DavidPostill
      DavidPostill almost 8 years
      You have a " (double quote) in the middle of your $env:psmodulepath which isn't there on my installation (C:\Users\DavidPostill\Documents\WindowsPowerShell\Modules;C‌​:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsP‌​owerShell\v1.0\Modul‌​es. I bet that is the cause of your problem.
    • Eric
      Eric almost 8 years
      I think that may be the problem. I've found msdn.microsoft.com/en-us/library/dd878326(v=vs.85).aspx but there seems to be a typo in it. The command to create a permanent and temporary change to the $env:psmodulepath is the same on that page.
    • Eric
      Eric almost 8 years
      DavidPostill, I did a $env:PSModulePath="C:\Users\myuserid\Documents\WindowsPowerS‌​hell\Modules;C:\Prog‌​ram Files (x86)\PowerShell Community Extensions\Pscx3\;C:\windows\system32\WindowsPowerShell\v1.0‌​\Modules;C:\Program Files\WindowsPowerShell\Modules" and it fixed the problem. You should rephrase your comment as an answer to the question.
    • ferventcoder
      ferventcoder almost 8 years
      Did the PowerShell upgrade complete successfully? I'd like to see what the logs state here. Something weird is definitely going on. Can you provide the log files for where PowerShell 5 upgrade was attempted?
    • ferventcoder
      ferventcoder almost 8 years
      I wonder if there is a bug with the PowerShell package or with Chocolatey. Not ruling out either right now.
    • DavidPostill
      DavidPostill almost 8 years
      @eric Answer added. Please remember the @ next time - I only noticed by accident that you had addressed a comment to me ;)
    • DavidPostill
      DavidPostill almost 8 years
      @Eric Where is the typo in the MS link? (it's not obvious)
    • Eric
      Eric almost 8 years
      The commands for To add a temporary value that is available only for the current session, run the following command at the command line and To add a persistent value that is available whenever a session is opened, add the following command to a Windows PowerShell profile: are identical. The comments at the bottom of the article mention it.
    • DavidPostill
      DavidPostill almost 8 years
      @Eric Ah. OK. Neither of those are the cause of the extra double quote though.
  • ferventcoder
    ferventcoder almost 8 years
    I'm most curious what caused the double quote in the first place.
  • DavidPostill
    DavidPostill almost 8 years
    @ferventcoder My Powershell upgraded to 5 successfully (with no double quote). That was a direct install though, I don't use Chocolatey
  • ferventcoder
    ferventcoder almost 8 years
    I would have expected that to work properly. I'm trying to determine if it is a bug in Chocolatey or the PowerShell package.
  • Eric
    Eric almost 8 years
    I think the chocolatey package that I installed that upgraded Powershell was the ChocolateyGUI: chocolatey.org/packages/ChocolateyGUI I also installed html-tidy, but I don't think that was the culprit chocolatey.org/packages/html-tidy