Last active
February 20, 2025 09:20
-
-
Save Diagg/c3ca51c8a3d9d7665fbaf4252b1346ef to your computer and use it in GitHub Desktop.
Run task as Trusted installer using Scheduled Task under system account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Run task as Trusted Installer From system context (Yeah, Intune, SCCM) | |
| # Should also work under Admin context (if not, remove all references to $P). | |
| # Credit due to : https://www.tiraniddo.dev/2019/09/the-art-of-becoming-trustedinstaller.html | |
| $a = New-ScheduledTaskAction -Execute notepad.exe | |
| $P = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrateurs" | |
| #$P = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" #Warning: the admin Group name is localised | |
| Register-ScheduledTask -TaskName 'TestTask' -Action $a -Principal $P | |
| $svc = New-Object -ComObject 'Schedule.Service' | |
| $svc.Connect() | |
| $user = 'NT SERVICE\TrustedInstaller' | |
| $folder = $svc.GetFolder('\') | |
| $task = $folder.GetTask('TestTask') | |
| #Start Task | |
| $task.RunEx($null, 0, 0, $user) | |
| #Kill Task | |
| $task.Stop(0) | |
| #remove task From Task Scheduler | |
| Unregister-ScheduledTask -TaskName 'TestTask' -Confirm:$false |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As Notepad is running in a non-interactive session you won't see it on screen, but
you can easily check that Notepad is running in the correct context using task manager:
If you need to the same with Powershell Scriptblock under Admin account, check this gist : https://gist.github.com/Diagg/64794cf25be9eeb52809a5b097873676