Thursday, December 10, 2009

No Web Browser, Need PowerShell

I recently found myself on a Windows Server 2003 machine without a functioning web browser and PowerShell wasn’t installed either.

No problem, I just opened notepad and started typing:

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"

Saved it as a command script and double-clicked it. PowerShell v2 installer downloads and runs, bam!

This would require tweaking for other processor architectures, other operating system versions, or older .NET installations.

Friday, December 11, 2009 3:18:58 AM (Cen. Australia Standard Time, UTC+09:30)
This is just too cool.
I have to try it out and, if it works, then I'll add it to my PowerShell toolbox.

Thanks for sharing,

Klaus
Comments are closed.