Sudo !! equivalent in PowerShell
$^
is a variable that expands to the last executed Powershell command.
You can run a command as another user using runas
, so the following works:
runas /user:domain\administrator $^
To shorten that up a bit, you can do some magic with aliases. Take a look at this Technet article for more info.
EDIT: One caveat - $^
only executes the first command in a pipeline or multi-command line. If you need to redo an entire command that is peppered with pipes or semicolons, use Invoke-History
instead (which defaults to the last full command in its entirety).