If you are already in powershell, type:
Start-Process powershell -verb runas
I write a sudo function to accomplish more powerful things, like executing something elevated and get the result in the same shell, for example:
sudo {rm fileThatNeedElevatedRightsToBeDeleted; ls}
Here is the code:
function sudo(){
param([String] $code)
$viejos = gps powershell
$here = add-quotes (get-location).path
$resultPath = [IO.Path]::GetTempPath() + "temp.result.xml";
$code = "set-location $here; function Run{$code};Run $args|Export-Clixml $resultPath"
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($code))
start-process PowerShell.exe -verb Runas -argumentlist '-encodedCommand',$encoded
$nuevos = gps powershell
$array = New-Object Collections.Generic.List[int]
$array2 = New-Object Collections.Generic.List[int]
$viejos | %{$array.add($_.ID)}
$nuevos | %{$array2.add($_.ID)}
$idTowait = $array2 | ?{$array -notcontains $_}
while(1){
$nuevos = gps powershell
$array2.Clear()
$nuevos | %{$array2.add($_.ID)}
if($array2 -contains $idTowait)
{sleep -Milliseconds 500}
else
{break;}
}
if(Test-Path $resultPath){
if((gi $resultPath).length)
{
Import-Clixml $resultPath
rm $resultPath
}
}
else
{"No results"};
}
Duplicate question - http://superuser.com/questions/108207/how-to-run-a-powershell-script-as-administrator
– vapcguy – 2015-07-16T17:56:11.517You can use
– Gerardo Grignoli – 2020-02-19T14:12:20.153gsudo
to elevate PowerShell commands:$hash = gsudo "(Get-FileHash ./protectedfile).Hash""