Tinus EngOps Wiki


OpsaC - Operating as PowerShell code



PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View Tinus IT Wiki

View my Photo Website

Run PowerShell as

tags: PowerShell categories: PowerShell-Basic

Table of Contents

Run PowerShell as Administrator

Enter in a PowerShell as User:

Start-Process "$psHome\powershell.exe" -Verb Runas -Wait

for PowerShell Core enter:

Start-Process "$psHome\pwsh.exe" -Verb Runas -Wait

Run a PowerShell-Script as Administrator

    [Parameter(Mandatory = $true)]

$ScriptFullName  = $MyInvocation.MyCommand.Source
$CurrentIdentity = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$IsAdministrator = $CurrentIdentity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

    Start-Process "powershell.exe" -ArgumentList "-File $($ScriptFullName) -Interface $($Interface)" -Verb Runas -Wait
    Write-Host "I'm running as Administrator $($Interface)!" -ForegroundColor Red
Read-Host -Prompt "Press any key to continue"

Run PowerShell as System

Enter in the Administrators PowerShell:

psexec.exe -i -s powershell.exe

PsExec is a tool written by Mark Russinovich (included in the Sysinternals Suite) and can downloaded here.

See also

Windows Sysinternals on Microsoft Docs

[ Top ] [ Blog ]