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.UseDefaultCredentials = true; >>"%~dpn0.cs"
echo wc.DownloadFile(@"", @"%~dpn0.installer.exe");}}} >>"%~dpn0.cs"
"%systemroot%\\framework\v3.5\csc.exe" /out:"%~dpn0.exe" "%~dpn0.cs"

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.

Thanks to @tathamoddie for the proxy-friendly fix.

One comment