Rants, rambles, news and notes from another geek

Shifting Powershell Arrays

In one of my recent posts, I showed a newer version of my ‘sudo for Powershell’ that was all writted in Powershell and left an open question about how to collect the variable arguments at the end.

Wes Haggard again comes through with the answer and points me to a post on the Powershell Blog called PowerShell Tip: How to “shift” arraysΓǪ

Using that tip, Wes gave me back a much tighter version of the elevation function:

function elevate
$file, [string]$arguments = $args;
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";

Killer! Thanks again Wes!