PowerShell Broken After Upgrade

After upgrading PowerShell from 4.0 to 5.1 on my Windows 7 laptop I’m unable to run most cmdlets. For example, if I open a new PS window and try to run Get-Service I get the following error:

get-service : The term ‘get-service’ 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-service
  •   + CategoryInfo          : ObjectNotFound: (get-service:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    
    

I get that for any cmdlet I try to run. Tab complete is also not working. However, something really weird happens when I try to tab complete. If I start typing the cmdlet and try to tab complete, the tab complete doesn’t work. However after I try to tab complete, then end up just typing the rest of the command, it works. Here is an example:

PS C:\Users\mcelreathm> get-service
get-service : The term ‘get-service’ 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-service
  •   + CategoryInfo          : ObjectNotFound: (get-service:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

PS C:\Users\mcelreathm> get-serv
get-serv : The term ‘get-serv’ 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-serv
  •   + CategoryInfo          : ObjectNotFound: (get-serv:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

PS C:\Users\mcelreathm> get-service

Status Name DisplayName


Running AdaptivaClient AdaptivaClient
Running AdminHelper.exe AdminHelper.exe
Running AdobeARMservice Adobe Acrobat Update Service

This seems to only make built in cmdlets available. But still no tab complete.

Has anyone seen this before/know if there is something I can do to fix this. I’m due for a new laptop at work but I’m not sure how long I have to wait for it.

Wow, Windows 7. I’m feeling nostalgic! At least it’s not Vista ;).

There actually are no “built-in” cmdlets; everything is an add-on. Some just get loaded by the console app by default. Try running “Get-Command -CommandType Cmdlet” in a new window, along with “Get-Module” and “Get-Module -ListAvailable” - you don’t need to paste the entire output here, but does it look like it used to?

Start by checking $env:PSModulePath. What’s it say?

Also confirm $PSVersionTable.

It’s worth noting that v5 doesn’t really bring a lot new to the table for Win7. I mean, the core cmdlets should definitely work, but you’re not going to get a bunch of new ones, because Win7 doesn’t come with them.

Did you do the upgrade running the powershell script as defined here:
https://docs.microsoft.com/en-us/powershell/wmf/5.1/install-configure

I would try reinstalling it and making sure you have elevated privileges when you run the install using the powershell script listed in the above link. It could be that it was installed previously with normal privileges and some things aren’t installed correctly.

I get this when trying to run Get-Command:

PS C:\Users\mcelreathm> Get-Command -CommandType Cmdlet
Get-Command : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
At line:1 char:1

  • Get-Command -CommandType Cmdlet
  •   + CategoryInfo          : NotSpecified: (:) [Get-Command], ArgumentOutOfRangeException
      + FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Microsoft.PowerShell.Commands.GetCommandCommand
    
    
    

However, Get-Module works fine.

$PSModulePath gives me the following:

PS C:\Users\mcelreathm> ($env:PSModulePath).split(‘;’)
C:\Users\mcelreathm\Documents\WindowsPowerShell\Modules
C:\Program Files (x86)\PowerShell Community Extensions\Pscx3
C:\Program Files\WindowsPowerShell\Modules
C:\windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules
C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Powershell\

I was keeping v4 on this machine in case I needed to author any MOFs for our existing v4 Pull server. But our client team is requiring us to upgrade to 5.1 because it’s required for a new SCCM rollout.

Yeah, “broke.” I’d try taking Rick’s suggestion and seeing if it fixes it. Beyond that, I don’t know what else to tell you to try.

I have actually uninstalled and reinstalled a bunch of times trying to fix this. I did originally run the .ps1 file to install. However, now when I uninstall v5.1, PowerShell is completely broken for me. When I try to open a new window or ISE window, they just close. I’ll see if I can get it to work in an elevated window and see if that helps.

Well, I tried uninstalling 5.1 and I can’t do anything in PowerShell so running the script in an elevated console is out of the question. It’s probably time to see if they can expedite my new Windows 10 laptop. Thanks for your input on this.

This is the error I get if I try to open PowerShell from a command prompt by the way:

C:\Users\mcelreathm>powershell
Windows PowerShell terminated with the following error:
Could not load type ‘System.Management.Automation.Runspaces.EarlyStartup’ from
assembly ‘System.Management.Automation, Version=3.0.0.0, Culture=neutral, Public
KeyToken=31bf3856ad364e35’.