Register-ScheduledJob as the system account (without having to pass in credentials)

Question:

I believe for Register-ScheduledTask you can specify -User "System"or do something like:

How do I do this with Register-ScheduledJob?

This command will be running the context of the local admin so it will have access to do this. I just don’t see this option in the cmdlet.

Here is an example of how to do this with the scheduled tasks cmdlet

edit: Does windows make this impossible by design? If I open an interactive PS session as the system (using psexec) and try to create a schedualed job I get an error:

This same command works fine when run as the local administrator account

Answer:

First use Register-ScheduledJob to create your PowerShell job.

Then use Set-ScheduledTask to change a startup account to the Local System or any other built-in accounts, i.e. SYSTEM, LOCAL SERVICE, NETWORK SERVICE, etc.

Use the following PS-script. Or download it from my GitHub Gist
The code is self-explanatory (I believe).
You can run it multiple times under an administrative account if you want to check how it works.

BTW, I prefer to use jobs (Register-ScheduledJob) over tasks because jobs allow me to embed PowerShell script blocks (strings) instead using of external script files. Look at -ScriptBlock below.

Also pay attention to -RunElevated. It is a must be.

Source:

Register-ScheduledJob as the system account (without having to pass in credentials) by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply