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.
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 the Security tab
Click Advanced
Click Add
Select Principal
Add your username (or Administrator if you want to work with it as admin)
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
Create a folder to mount the image
Run this command to mount the image:
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:
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.
Boom! PowerShell in Windows RE
Start PowerShell
and enjoy!
To get out of safe mode you'll have to run msconfig from the command line and uncheck Safe Boot.
start powershell
from the command prompt. Does this work in WinRE?start powershell
andpowershell
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 .NetC:\Windows\System32\WindowsPowerShell\v1.0
but you might need to search in windows first.powershell
command from its directory with no success. I had the same result as George Duckett below.