Powershell on Windows Vista and Windows 7 runs restricted and not-elevated by default. Microsoft did a good job when they invented the so called UAC (User Account Control). As ususal, Microsoft started something new and did not finish it yet – the product is still not feature-complete. Well, probably it’s their philosophy to create thousands of products in a vertical manner, the user then is left all alone finding out how to dive into the features from a horizontal perspective…
What i mean: PowerShell runs restricted and has NO SUDO command. For sake of christ, there is a workaround.
First, find out the location of your profile.ps1. it easy as:
PS C:\> $profile
Probably this script does not exist by default. At least on my systems this was the case. So create it.
When created / if it does exist do:
PS C:\> notepad.exe $profile
This should open your profile.ps1 script in notepad..
Edit this Script to include:
$file, [string]$arguments = $args;
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;
set-alias sudo elevate-process;
Now you’re almost done. After starting a new PowerShell session – even a non-elevated one – you can run commands elevated by using the sudo command.
PS C:\> sudo notepad.exe
If the new PowerShell session should display a warning regarding the execution of scripts, check out my older posts (using the site search), i’ve postet a solution for that.