Skip to content

Instantly share code, notes, and snippets.

@tathamoddie
Created August 5, 2010 03:48

Revisions

  1. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ if %PSVer% geq 2 goto already_installed
    echo PowerShell %PSVer% is currently installed (but will be upgraded)

    :install
    echo PowerShell 2 is required for this script but is not install on your machine.
    echo PowerShell 2 is required for this script but is not installed on your machine.
    echo It will now be installed automatically.
    pause
    echo Downloading PowerShell 2
  2. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 32 additions and 4 deletions.
    36 changes: 32 additions & 4 deletions RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,29 @@
    @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 Only works on XP SP3 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
    ver | find "5.1.2600" > nul
    if %ERRORLEVEL% neq 0 goto not_xp_sp3

    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command "exit $PSVersionTable.PSVersion.Major"
    if not exist "%systemroot%\microsoft.net\framework\v3.5\csc.exe" goto not_netfx_35

    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 PowerShell 2 is required for this script but is not install on your machine.
    echo It will now be installed automatically.
    pause
    echo Downloading PowerShell 2
    echo class Program { public static void Main() { >"%~dpn0.cs"
    echo using (var wc = new System.Net.WebClient()) { >>"%~dpn0.cs"
    @@ -26,15 +34,35 @@ echo wc.DownloadFile(@"http://download.microsoft.com/download/E/C/E/ECE99583-200
    "%~dpn0.exe"
    if %errorlevel% neq 0 goto :EOF
    echo Installing PowerShell 2
    "%~dpn0.installer.exe" /quiet
    "%~dpn0.installer.exe"
    set InstallResult=%errorlevel%
    if %InstallResult% neq 0 goto install_failed
    del "%~dpn0.cs"
    del "%~dpn0.exe"
    del "%~dpn0.installer.exe"
    goto :EOF

    :install_failed
    echo PowerShell 2 installation failed.
    exit 1
    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
    exit 1
    goto :EOF

    :not_xp_sp3
    echo This script requires XP SP3. Install now from:
    echo http://www.microsoft.com/downloads/details.aspx?familyid=2FCDE6CE-B5FB-4488-8C50-FE22559D164E
    exit 1
    goto :EOF

    :not_netfx_35
    echo This script requires .NET Framework 3.5. Install now from:
    echo http://www.microsoft.com/downloads/details.aspx?FamilyId=333325FD-AE52-4E35-B531-508D977D32A6
    exit 1
    goto :EOF

    :already_installed
  3. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ echo wc.DownloadFile(@"http://download.microsoft.com/download/E/C/E/ECE99583-200
    "%~dpn0.exe"
    if %errorlevel% neq 0 goto :EOF
    echo Installing PowerShell 2
    "%~dpn0.installer.exe"
    "%~dpn0.installer.exe" /quiet
    del "%~dpn0.cs"
    del "%~dpn0.exe"
    del "%~dpn0.installer.exe"
  4. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    @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/

    @echo off

    ver | find "XP" > nul
    if %ERRORLEVEL% neq 0 goto not_xp

    @@ -20,20 +20,23 @@ 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" /out:"%~dpn0.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"
    goto exit
    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 exit
    goto :EOF

    :already_installed
    echo PowerShell 2 or higher is already installed at %SystemRoot%\system32\WindowsPowerShell\
    goto exit

    :exit
    goto :EOF
  5. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    REM Based on http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/
    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/

    @echo off

  6. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    REM Based on http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/
    REM Only works on XP with .NET 3.5. Only for dev boxes, not designed for servers.

    @echo off

  7. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ REM Based on http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powersh
    @echo off

    ver | find "XP" > nul
    if %ERRORLEVEL% == 1 goto not_xp
    if %ERRORLEVEL% neq 0 goto not_xp

    if not exist %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe goto install

  8. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    REM Originally from http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/
    REM Based on http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/

    @echo off

  9. tathamoddie revised this gist Aug 5, 2010. 1 changed file with 31 additions and 2 deletions.
    33 changes: 31 additions & 2 deletions RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,37 @@
    REM Originally from http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/

    @echo off

    ver | find "XP" > nul
    if %ERRORLEVEL% == 1 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.DownloadFile(@"http://download.microsoft.com/download/1/1/7/117FB25C-BB2D-41E1-B01E-0FEB0BC72C30/WindowsServer2003-KB968930-x86-ENG.exe", @"%~dpn0.installer.exe");}}} >>"%~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"
    "%~dpn0.installer.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
  10. tathamoddie created this gist Aug 5, 2010.
    8 changes: 8 additions & 0 deletions RequiresPowerShell.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    REM Originally from http://blog.codeassassin.com/2009/12/10/no-web-browser-need-powershell/

    echo class Program { public static void Main() { >"%~dpn0.cs"
    echo using (var wc = new System.Net.WebClient()) { >>"%~dpn0.cs"
    echo wc.DownloadFile(@"http://download.microsoft.com/download/1/1/7/117FB25C-BB2D-41E1-B01E-0FEB0BC72C30/WindowsServer2003-KB968930-x86-ENG.exe", @"%~dpn0.installer.exe");}}} >>"%~dpn0.cs"
    "%systemroot%\microsoft.net\framework\v3.5\csc.exe" /out:"%~dpn0.exe" "%~dpn0.cs"
    "%~dpn0.exe"
    "%~dpn0.installer.exe"