In this article, I am going to show how to configure your computer to start PowerShell with administrative privileges every time you log on to your computer.
Run the Code
Copy the code below in your PowerShell Session or PowerShell ISE. Once copied, run it. The code was tested on Windows Server 2016.
$Action=New-ScheduledTaskAction -Execute "powershell.exe" $Trigger=New-ScheduledTaskTrigger -AtLogOn $Set=New-ScheduledTaskSettingsSet $Principal=New-ScheduledTaskPrincipal -UserID "$env:username" -LogonType Interactive -RunLevel Highest $Task=New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Set -Principal $Principal Register-ScheduledTask -TaskName PowerShellAtLogon -InputObject $Task
After executing, review your work in the graphical user interface (taskschd.msc). That looks good.
Log off and log on to check if it works.
For further information about Scheduled Jobs, see also: