It’s no secret that I’m a huge PowerShell fan. I’ve been very excited to start using all the handy new tools in PowerShell 2.0 RTM, but I still need PowerShell 1.0 for backwards compatibility testing. While there are quite a few options out there to do this, I even found someone who figured out how to make PowerShell portable, I didn’t need anything fancy, complex or expensive. Just a simple way to easily test my commands in PowerShell 2.0 and 1.0.
With the announcement of Windows XP Mode a little dinging noise went off in the back of my head. “Hey,” I thought, “why not just make PowerShell 1.0 into an XP Mode application?” We have a winner! Then, once XP Mode was released, I found out that no matter what you do Microsoft has decided to block executables in %windir% (C:\Windows) from XP Mode. That’s okay, where there is a will there is a way, right? In this case the answer is, yes.
I won’t go over the PowerShell and XP Mode install parts in detail, but, in summary, you need to be running Windows 7 Ultimate, Enterprise or Professional, download and install Windows Virtual PC [RC] and XP Mode [RC] on Windows 7, and then .NET 2.0+ and PowerShell 1.0 for Windows XP 32-bit on the Windows XP Mode virtual machine for this XP Mode trickery to work. In addition to the XP Mode and PowerShell components you need a handy little tool written by the master of all things Windows, Mark Russinovich, called Junction.
Virtual PC [RC] and XP Mode [RC]:
http://www.microsoft.com/windows/virtual-pc/download.aspx
.NET 3.5 SP1 redistributable:
PowerShell 1.0:
http://www.microsoft.com/.../powershell/download.mspx
Junction:
http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx
Is that the sound of mental bells I hear ringing? For those that don’t have the mental bells ringing, junction is the pre-Vista/2008 version of mklink. Junction creates a symbolic NTFS link between two folders. It’s like a shortcut, but Windows treats the “linked” directory like it was the real directory. In other words, the trick to tricking XP Mode is to create a junction to the folders which contain the tools you want to use in XP Mode.
To be on the safe side I created a link/junction from “C:\Program Files” to the PowerShell directory, C:\WINDOWS\system32\windowspowershell\v1.0. Here is the command I used, from the command prompt, after extracting junction to C:\Windows\System32.
junction "C:\Program Files\Shell of Power" "C:\WINDOWS\system32\windowspowershell\v1.0"
And, no, you don’t have to use “Shell of Power” as the folder name. It doesn’t matter what name you use, but whatever folder name you do choose it can’t exist before you run junction.exe.
Now create a shortcut from “C:\Program Files\Shell of Power\powershell.exe” to “C:\Documents and Settings\All Users\Start Menu\Programs” and delete the silly “Shortcut to” part if you did the drag and drop method. Log Off and hibernate the XP Mode VM (just close the window, default action is to hibernate). Pull up your “Windows XP Mode Applications” and you will see “powershell (Windows XP Mode)” in the list. Click the link, wait for the XP Mode application to spin up, and voila!
Let’s take this one step further, shall we? Say you also want command prompt from XP Mode. I like to use it to do ping, telnet, and tracert tests from outside my VPN connection without actually turning off my VPN connection. Simple. Just make a shortcut from “C:\Windows\System32\cmd.exe” to the “Shell of Power” folder. Then create a second shortcut from the cmd.exe shortcut in “Shell of Power” to the All Users program list. And, once again, viola! Rinse and repeat for any tool or program in %windir% you want to use as an XP Mode application.
That just about covers it. My not-so-secret way of tricking XP Mode into letting us admins and scripters use PowerShell 1.0 and the good old Windows XP system tools on your shiny new Windows 7 installation. Oh, and thank you for XP Mode, Microsoft!
#James Kehr
Get-Member $OW | ?{$_.title -eq "System Administrator"`
-and $_.certification -contains 'MCITP:SA 2008, MCSE 2000, MCDST, Network+, A+'}
New-Variable -name company -value 'ORCS Web, Inc.' -description ‘www.orcsweb.com | 1.888.313.9421’
You can subscribe to James Kehr feed via RSS to receive updates when new entries are posted.