Powershell Tip #53: Run PowerShell as SYSTEM (NT AUTHORITY\SYSTEM)

By | October 8, 2015

Tip: You can run PowerShell as NT AUTHORITY\SYSTEM in interactive mode or as a scheduled task.

Solution 1 : Interactive

run-cmd-nt-authority-system-user-powershell

Note: PsExec is a tool written by Mark Russinovich (included in the Sysinternals Suite) and can downloaded here.

Solution 2 : Interactive

1) Open cmd.exe as administrator

open-cmd-system

2) psexec.exe -i -s powershell.exe

Note: PsExec is a tool written by Mark Russinovich (included in the Sysinternals Suite) and can downloaded here.

open-cmd-system-powershell

3) A new shell will open under “NT AUTHORITY\SYSTEM

powershell-local-system-psexec

Solution 3 : Scheduled task

  • Open Task Scheduler (taskschd.msc)
  • Create a Basic Task

Create-Scheduled-Task-Powershell-As-NtAuthority-System-1

  • Set a trigger (for this demo I choose “One time”)

Create-Scheduled-Task-Powershell-As-Nt-Authority-System-2

  • Set the start time (Synchronize across time zones = UTC)

Create-Scheduled-Task-Powershell-As-Nt-Authority-System-3

  • Start a program

Create-Scheduled-Task-Powershell-As-Nt-Authority-System-4

  • Settings

Program/script:

Add arguments (optional):

Get-CurrentUser.ps1

Create-Scheduled-Task-Powershell-As-Nt-Authority-System-5

  • Check the box “Open the Properties dialog for this task when I click Finish”

Create-Scheduled-Task-Powershell-As-Nt-Authority-System-6

  • Change user to “SYSTEM” and configure for the OS of this machine (in my case it is Windows 10)

Note: I didn’t checked the box “Run with highest privileges” in this case as not needed but somtimes you could need that enabled.

Create-Scheduled-Task-Powershell-As-NtAuthority-System-7

  • If I check the content of C:\demo\whoami.txt, I see that the script successfully ran under the context of NT AUTHORITY\SYSTEM

Create-Scheduled-Task-Powershell-As-NtAuthority-System-step-8

As we can see, the current user was indeed NT AUTHORITY\SYSTEM (the variable $env:USERNAME will show as “MACHINE$”).


previous-buttonnext-button

Leave a Reply

Your email address will not be published.