The following script will setup a scheduled task to run as any user by running the task as the ‘Users’ group.
Please note, this is using the .Net method of creating the task, as there’s more options using the .Net method rather than using the PowerShell cmdlet:
New-ScheduledTask
The information to help build the below PowerShell script was taken from the website which covers all the information you need https://msdn.microsoft.com/en-us/library/windows/desktop/aa383607(v=vs.85).aspx
This file contains 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
# This will create a scheduled task which will run a UserLogonScript for any user that logs on changing the regional settings for the user to Australia. | |
$ShedService = New-Object –comobject 'Schedule.Service' | |
$ShedService.Connect() | |
$Task = $ShedService.NewTask(0) | |
$Task.RegistrationInfo.Description = 'UserLogonScript' | |
$Task.Settings.Enabled = $true | |
$Task.Settings.AllowDemandStart = $true | |
$trigger = $task.triggers.Create(9) | |
$trigger.Enabled = $true | |
$action = $Task.Actions.Create(0) | |
$action.Path = 'PowerShell.exe' | |
$action.Arguments = '-ExecutionPolicy Unrestricted -File c:\UserLogonScript.ps1' | |
# $action.WorkingDirectory = '' | |
$taskFolder = $ShedService.GetFolder("\") | |
$taskFolder.RegisterTaskDefinition('UserLogonScript', $Task , 6, 'Users', $null, 4) |