Friday, November 08, 2013

Automated install of PowerShell on Windows XP

The problem: I want a batch script to perform an unattended/silent install of PowerShell on Windows XP.

We need to download the PowerShell installer from Microsoft, but it needs to be downloaded from an HTTP server. I'm not aware of an easy way to download files from the command-line or script in Windows XP, other than the FTP command. But what we can do easily, is to download cURL via FTP first.

So we need to download 4 things from the batch script:
  1. We need to get 7-Zip to extract cURL.
  2. We need to get cURL (or wget) to download PowerShell.
  3. Download and install .NET Framework 2 since it's required by PowerShell.
  4. Finally we download PowerShell itself from Microsoft via HTTP.
Step 1: download 7-Zip archiver's command-line version (7za.exe) from an FTP server. You need to search for any FTP server that hosts 7za.exe.

This FTP script would work to get 7za:
open ftp.cadwork.ch
user
anonymous

cd /DVD_V17/CADWORK.DIR/COM/
bin
get 7za.exe
Step 2: download curl from one of the official FTP mirrors if you can. I didn't have any luck with the official mirrors so I just searched around until I found an older version.

This FTP script would work to get curl 7.19.3: 
open ftp.gr.freebsd.org
user
anonymous

cd /pub/net/ftp/curl/
bin
get curl-7.19.3-win32-nossl.zip
Now we can use 7za.exe to extract the curl zip file.

Step 3: download .NET Framework 2.0 and install it silently:
curl -O http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe
start /wait "Installing .NET" NetFx20SP2_x86.exe /qb
Step 4: download PowerShell for Winfows XP and install it silently:
curl -O http://download.microsoft.com/download/E/C/E/ECE99583-2003-455D-B681-68DB610B44A4/WindowsXP-KB968930-x86-ENG.exe
start /wait "Installing PowerShell" WindowsXP-KB968930-x86-ENG.exe /passive /log:powershell-install.log
The final batch file to put it all together is here.

If you're curious why I'd be using Windows XP: I sometimes need to test old software. In this case, I want to install Visual C++ 6 to see if some old C++ code compiles without warnings before I start the process of converting it to a newer Visual Studio.

Note: I used FileWatcher.com to search for FTP servers that host the 7-Zip command-line tool (7za.exe) and cURL.

Post a Comment