7

on a windows server 2008 r2 sp1 machine, i used chocolatey to install the AWSTools.Powershell package. this, in turn, installed powershell 3. now, powershell is hopelessly broken and i can't figure out any way of fixing it or uninstalling and reinstalling it.

i fear my only answer is completely rebuilding the machine, but wanted to ask if there's a way to fix it.

powershell actually runs, it just seems it can't find any of the build-in cmdlets. it seems it does find aliases, but can't execute what's under them. for example, issuing an ls to look at directory contents yields:

PS C:\Users\Administrator> ls
ls : 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
+ ls
+ ~~
    + CategoryInfo          : ObjectNotFound: (Get-ChildItem:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

it may be that there's just some execution of some script missing at the start that sets up the environment. if you know more than me and can offer some assistance and can make it so that i don't have to rebuild this machine, i would be very happy.

Dave Rael
  • 1,759
  • 2
  • 16
  • 21
  • How about download and reinstall Windows management framework 3 (powershell V3 included) from MS? http://www.microsoft.com/en-us/download/details.aspx?id=34595. If you encounter problem when installing then you might need to check if you have appropriate .Net framework version installed. I believe .Net Framework 4.0 or 4.5 is the requirement for PS V3. – Peter Jul 15 '13 at 16:18
  • @Peter. thanks. i had tried to do that. it just told gave me a dialog saying it was already installed and i had no options except an ok button that closed out the installer. i started searching for a way to uninstall to try to reinstall, but didn't see any such option. – Dave Rael Jul 15 '13 at 16:31
  • 1
    run: "sfc /scannow" from an elevated prompt. – x0n Jul 15 '13 at 16:36
  • @DaveRael Check this link out http://www.microsoft.com/en-us/download/details.aspx?id=34595. If you click "download" you will see several versions of windows management framework V3 (I believe one of the x64 is on your computer). Compare this list to whatever in your control panel/program and features/view installed updates you should be able to see the update which containing powershell currently running. Find it and remove it this way. – Peter Jul 15 '13 at 16:53
  • Are you running a special AWSTools configured console (or psc1 file)? If you run `c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile` do you still have problems? – Keith Hill Jul 15 '13 at 19:33
  • thanks guys. @Keith - i have tried both the normal console and aws configured one - both same thing. tried the full path to the executable as you advised with -noprofile - still same problem. – Dave Rael Jul 16 '13 at 01:10
  • 1
    @x0n - running the scan now, will report back with results. – Dave Rael Jul 16 '13 at 01:11
  • 1
    scan did say it found and fixed some corruption, but the powershell problem remains. – Dave Rael Jul 16 '13 at 11:19

2 Answers2

10

A little bit late to the game, but recently ran into this problem. I found that my PSModulePath did not include an important path. You can view your PSModulePath by running this command:

$env:PSModulePath

To add the needed path you can run this command:

$env:PSModulePath = $env:PSModulePath + ";C:\Windows\system32\WindowsPowerShell\v1.0\Modules\"

Scott
  • 528
  • 6
  • 10
  • Thank you kind sir! my output was "\\[A Server]\Users\[My USerName]\My Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\" which obviously didn't work! But your fix did. – user917170 Apr 30 '15 at 02:53
  • I haven't seen this problem again, but with a couple votes, this answer's obviously helpful. Accepting. – Dave Rael Aug 03 '15 at 14:10
  • This just fixed this issue for me; Our inept/incompetent IT admins pushed an update they probably shouldn't have and hosed my dev box. Thanks! – honestduane Dec 22 '15 at 17:15
  • This fixed it for me -- an upgrade from v4 to v5 seems to have wiped $PSModulePath env var; creating it again fixed everything. – Ewen Cartwright Feb 07 '17 at 15:16
3

This is a very old thread, but since I found it whilst troubleshooting the exact same issue - I thought I'd mention how I resolved it.

First the problem as I experienced it:

I had PowerShell 2.0 on Windows 7, then used choco to install/upgrade to PowerShell 4.0:

choco upgrade powershell

That updated my system to 4.0, but when I opened PowerShell, the upgrade broke most of the basic cmdlets such as Get-ChildItem (aka dir).

After fumbling about online for a while, I thought I'd reinstall from the MS Website... but first I uninstalled from choco.

choco uninstall powershell

And since it was choco that broke it to begin with I thought I'd give it one more try to install cleanly with the following command:

choco install powershell --force

And low, that fixed the problem. So I stopped there. Hopefully that's helpful to someone. Good luck!

Ejoso
  • 150
  • 1
  • 7
  • 1
    Uninstalling and reinstalling seems like a nobrainer - too long ago, don't remember if I tried that, but glad to have this here for folks who find this. – Dave Rael Aug 03 '15 at 14:11
  • Yeah totally - I was hoping to illustrate the process with choco as distinct however because it (strangely) hadn't occurred to me. I was planning to go about it via MS website instead. – Ejoso Aug 03 '15 at 16:03