Configuring the automatic start of PowerShell at every logon

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
$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

Tagged as: ,

5 replies »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.