sudo for Windows Powershell
 

Based on this page, I have written a TypeExtension of ScriptBlock which will run that script block in an elevated instance of Powershell and return the results.

Simply place this snippet in your custom TypeExtension file and run Update-TypeData

<Type>
<Name>System.Management.Automation.ScriptBlock</Name>
<Members>
<ScriptMethod>
<Name>RunAsAdmin</Name>
<Script>
$temppath = "$ENV:TEMP\PoSH-sudo-$PID.xml";

$psi = new-object System.Diagnostics.ProcessStartInfo "powershell";
$psi.Arguments = "-Command Set-Location `"$((Get-Location).Path)`"; $this | Export-Clixml -Path `"$temppath`"";
$psi.Verb = "runas";
$psi.WindowStyle = "Hidden";

[System.Diagnostics.Process]::Start($psi).WaitForExit();

Import-Clixml -Path "$temppath";
Remove-Item $temppath;
</Script>
</ScriptMethod>
</Members>
</Type>

Now, to use it, simply put .RunAsAdmin() after a ScriptBlock:

PS> $PID
52280
PS> {$PID}.RunAsAdmin()
14880

You can even recurse (you'll only get one UAC prompt though, since it's not elevating the second one):

PS> {{$PID}.RunAsAdmin(),$PID}.RunAsAdmin(),$PID
12812
19388
52280

Comments? Bugs? Email me: justarandomgeek [at] gmail
put "PoSH-sudo" in the subject line to guarantee that I get it