Skip to content

Instantly share code, notes, and snippets.

@marckean
Created May 6, 2017 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marckean/bb15ba9f9c9942dfcfd54af098154eb1 to your computer and use it in GitHub Desktop.
Save marckean/bb15ba9f9c9942dfcfd54af098154eb1 to your computer and use it in GitHub Desktop.
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment