Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have tried to access PowerShell from the Command Prompt in Windows Recovery Environment with no success. I am able to run VBScripts there without a problem, and I am now wondering if there is some way to run my PowerShell commands from there as well.

Can PowerShell be used within WinRE, or am I stuck with VBScript/JScript support at best?

Please note that this is about WinRE and not WinPE!

EDIT

EBGreen had commented about adding additional components to WinPE that would allow the use of PowerShell within that environment. Could the same approach be taken with WinRE?

share|improve this question
    
You can start powershell from the command line with start powershell from the command prompt. Does this work in WinRE? –  George Duckett Oct 24 '12 at 19:04
    
I've tried both start powershell and powershell from the WinRE Command Prompt with no success - says those are unknown commands. They work fine within Windows though. I wonder if this has anything to do with PowerShell's dependency on .Net –  Riaan Oct 24 '12 at 22:45
    
Ok, final suggestion, try navigating to the powershell exe and running it. From here, Path to Powershell.exe (v 2.0) I guess it's going to be something like C:\Windows\System32\WindowsPowerShell\v1.0 but you might need to search in windows first. –  George Duckett Oct 25 '12 at 6:51
    
I had initially tried running the powershell command from its directory with no success. I had the same result as George Duckett below. –  Riaan Oct 29 '12 at 13:41

3 Answers 3

up vote 6 down vote accepted

You can do this, but you'll need a Windows 8 install and the Windows 8 ADK with Windows PE (it's a rather large download). I'm fairly certain you can use this Win RE image on a Windows 7 install once you get it going, but I'm not 100% sure.

There's a few other ways you may be able to accomplish this, including building a Windows PE image with the recovery environment tools installed, but this is probably the easiest method, and will result in PowerShell being available whenever your machine enters the recovery environment vs. having to boot to it using removable media.

Find your WinRE.wim

I used Everything to find mine. It happened to be hiding in C:\Recovery\67c45205-df4a-11e1-8fd9-9103ad6af7ef. This may be true for you as well. To take a look you'll have to disable Hide Protected System Files. This setting is lurking in Explorer under View, Options, Change Folder and Search Options, View tab.

Unhide the goodies

Change the permissions

You'll have to mess with the permissions to even see the permissions on this folder. Messing with permissions always make a little nervous, but forge ahead if you dare. I simply added my username to the security permissions with full control.

Right click Recovery, select properties

Open properties

Open the Security tab

Click the security tab

Click Advanced

Ya know, if you need this much help you probably shouldn't be doing this actually...

Click Add

Messing with security permissions can cause serious pain

Select Principal

But screenshots are fun and give me all teh rep

Add your username (or Administrator if you want to work with it as admin)

Now you know my super secret real name, zomg!

Copy WinRE.wim

I elected to copy the .wim so I could work with it, but I suppose you could work with it directly as well. If you chose to work with it directly, modify command appropriately. I copied mine to C:\winre\.

Add PowerShell to the image

Now that we have a .wim to work with, we can add the necessary components for PowerShell. You will need the appropriate components of Windows ADK, including Windows PE.

Mount the image

Find Deployment and Imaging Tools, right click, and run as Administrator

Seriously, if you couldn't find this on your own turn back now

Create a folder to mount the image

At least I'm not letting people copy and paste this stuff

Run this command to mount the image: Screenshots are great for preventing copy and paste!

Add the required packages

There's a little back and forth involved in the following commands, and things have to be done in order. We need to install the following packages:

  • WinPE-WMI
  • WinPE-NetFX4
  • WinPE-Scripting
  • WinPE-PowerShell3
  • WinPE-DismCmdlets
  • WinPE-StorageWMI
  • WinPE-HTA

We'll also have to install en-us (substitute for your preferred language) packages for each of the above packages as well.

Start with this:

dism /image:C:\winre\mount /add-package /packagepath:"C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\WinPE-WMI.cab

Then run this:

dism /image:C:\winre\mount /add-package /packagepath:"C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Windows Preinstallation Environment\amd64\WinPE_OCs\en-us\WinPE-WMI_en-us.cab

Now push Up twice to recall the first command, and replace WMI with NetFX4. Repeat this until you have installed all the required components along with the required language. Remember to do this in order.

Finish the image

Now that all the packages are in place, we need to commit our changes and finish our WinRE.wim. From there we can build a .iso, test it in Hyper-V, and copy the WinRE.wim to our recovery file so we have access to PowerShell the next time the system crashes.

Unmount and Commit

Run the following command to dismount the image and commit the changes: The above command sucked to type, so I'll let C+P slide on that one...

Several things can go wrong here, and the error messages are terribly misleading. Make sure there are no typos and you have nothing open related to these files, not even Explorer.

Replace original WinRE.wim and test

Make a backup of your original WinRE.wim and replace it with the new one. Now run msconfig and open the Boot tab. Check Safe Boot and select Alternate Shell. Reboot and give it a try.

TROLOLOL You're stuck in safe boot now! I restarted three times before I realized this setting sticks...

Boom! PowerShell in Windows RE

Start PowerShell and enjoy!

Ahh, the beautiful blue PowerShell... Sweet victory.

To get out of safe mode you'll have to run msconfig from the command line and uncheck Safe Boot.

share|improve this answer
1  
slow ... clap –  William Jackson Oct 29 '12 at 13:30
    
Thanks for the extensive answer, Tanner! This is exactly what I needed. –  Riaan Oct 29 '12 at 13:36
1  
Just in case your WinRE image is in one of those OEM recovery partitions, you can use Visual BCD Editor to take a look at the Recovery boot entry and find the path to the image. –  Bob Oct 29 '12 at 15:35
  1. Windows PowerShell requires the Microsoft .NET Framework. [source]
  2. Windows Recovery Environment is based on Windows PE. [source]
  3. Windows PE does not support the .NET Framework. [source]

Therefore, PowerShell cannot be used in WinRE.

share|improve this answer
    
Yes, I thought it was probably because of those MS.Net dependencies. This answer is definitely valid for default unmodified installs. Thanks William! –  Riaan Oct 29 '12 at 13:38

Right, I tried a lot of stuff and came to the conclusion it's not going to work. William's answer provides evidence to back this up.


I made a note of where powershell is. On my machine it's in c:\windows\system32\windowspowershell\v1.0\powershell.exe and in c:\windows\syswow64\windowspowershell\v1.0\powershell.exe.

The shortcut in administrative tools points to the syswow64 one.

I then restarted into recovery mode and got to the command prompt.

The first thing I noticed is that I can't get to the c drive.

So, I ran diskpart then entered the command list vol to get a list of avaiable drives. On my machine my C drive was called my D drive in the recovery console.

So I exited diskpart by typing exit, then in the command console typed d:, followed by cd\windows\syswow64\windowspowershell\v1.0.

Note that if you do it in stages, using dir to confirm folder names it doesn't show everything (namely the v1.0 folder).

Once there I crossed my fingers and typed powershell, only to receive the message:

The subsystem needed to support the image type is not present

I googled the error message above for a bit, but couldn't find anything that would indicate powershell might work.


I also tried the other powershell.exe in system32 but got no message at all (no didn't recognise the command or anything.

enter image description here

share|improve this answer
    
This doesn't work. Thanks George. –  Riaan Oct 29 '12 at 15:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.