Created
August 5, 2010 03:48
-
-
Save tathamoddie/509197 to your computer and use it in GitHub Desktop.
Batch file to automatically detect, download and install PowerShell 2 on to an XP SP3 machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM Based on http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/ | |
@echo off | |
ver | find "XP" > nul | |
if %ERRORLEVEL% neq 0 goto not_xp | |
if not exist %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe goto install | |
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "exit $PSVersionTable.PSVersion.Major" | |
set PSVer=%errorlevel% | |
if %PSVer% geq 2 goto already_installed | |
echo PowerShell %PSVer% is currently installed (but will be upgraded) | |
:install | |
echo Downloading PowerShell 2 | |
echo class Program { public static void Main() { >"%~dpn0.cs" | |
echo using (var wc = new System.Net.WebClient()) { >>"%~dpn0.cs" | |
echo wc.UseDefaultCredentials = true; >>"%~dpn0.cs" | |
echo wc.DownloadFile(@"http://download.microsoft.com/download/E/C/E/ECE99583-2003-455D-B681-68DB610B44A4/WindowsXP-KB968930-x86-ENG.exe", @"%~dpn0.installer.exe");}}} >>"%~dpn0.cs" | |
"%systemroot%\microsoft.net\framework\v3.5\csc.exe" /out:"%~dpn0.exe" "%~dpn0.cs" | |
"%~dpn0.exe" | |
echo Installing PowerShell 2 | |
"%~dpn0.installer.exe" | |
goto exit | |
:not_xp | |
echo This script only expects to work on XP, which is not your OS. | |
echo Install PowerShell manually from http://microsoft.com/powershell | |
goto exit | |
:already_installed | |
echo PowerShell 2 or higher is already installed at %SystemRoot%\system32\WindowsPowerShell\ | |
goto exit | |
:exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment