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
@echo off | |
REM If PowerShell 2 is not installed, this script will automatically download and install it. | |
REM Only works on XP with .NET 3.5. Only for dev boxes, not designed for servers. | |
REM Based on http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/ | |
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.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials; >>"%~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" /nologo /out:"%~dpn0.exe" "%~dpn0.cs" | |
"%~dpn0.exe" | |
if %errorlevel% neq 0 goto :EOF | |
echo Installing PowerShell 2 | |
"%~dpn0.installer.exe" | |
del "%~dpn0.cs" | |
del "%~dpn0.exe" | |
del "%~dpn0.installer.exe" | |
goto :EOF | |
: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 :EOF | |
:already_installed | |
echo PowerShell 2 or higher is already installed at %SystemRoot%\system32\WindowsPowerShell\ | |
goto :EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment