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.
See also
For further information about Scheduled Jobs, see also:
How to schedule software installation with PowerShell
Monitoring Windows PowerShell: Enable Module Logging
PowerShell: How to automatically restart applications when they are closed
Categories: PowerShell
Hi, Raakesh,
Great! You´re welcome.
Best Regards,
P
LikeLike
Thanks much, Patrick. It worked!
LikeLike