SID-500

Home » PowerShell » Configuring the automatic start of PowerShell at every logon

Configuring the automatic start of PowerShell at every logon

In this article, I will show you 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

Unbenannt.JPG

After executing, review your work in the graphical user interface (taskschd.msc). That looks good.

Unbenannt.PNG

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

If you want to monitor PowerShell, activate logging: Monitoring Windows PowerShell: Enable Module Logging


3 Comments

  1. Thanks much, Patrick. It worked!

    Like

  2. pewa2303 says:

    Hi, Raakesh,
    Great! You´re welcome.
    Best Regards,
    P

    Like

  3. […] For scheduling the automatic start of PowerShell at logon see my article Configuring the automatic start of Powershell at every logon. […]

    Like

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 )

Google+ photo

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

Connecting to %s

Categories

Who is the blogger?

My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on WordPress.com