OpsaC - Operating as PowerShell code
published: January 28, 2019 author: Tinu tags: PowerShell categories: PowerShell-Basic
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
[CmdletBinding()]
param(
[ValidateSet("VMXNet3","E1000")]
[Parameter(Mandatory = $true)]
[String]$Interface
)
$ScriptFullName = $MyInvocation.MyCommand.Source
$CurrentIdentity = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$IsAdministrator = $CurrentIdentity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if(-not($IsAdministrator)){
Start-Process "powershell.exe" -ArgumentList "-File $($ScriptFullName) -Interface $($Interface)" -Verb Runas -Wait
}else{
Write-Host "I'm running as Administrator $($Interface)!" -ForegroundColor Red
}
Read-Host -Prompt "Press any key to continue"
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.
Windows Sysinternals on Microsoft Docs