Created
August 18, 2021 18:53
-
-
Save rezarahimian/1fab1dd0c086dc848f45b957dbbefc1c to your computer and use it in GitHub Desktop.
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
$Principal = New-ScheduledTaskPrincipal -GroupId 'BUILTIN\Users' | |
$Command = Join-Path $env:SystemRoot -ChildPath 'System32\WScript.exe' | |
$Argument = '//NoLogo //B //T:120 "C:\Windows\LogonScript.vbs"' | |
$TaskAction = New-ScheduledTaskAction -Execute $Command -Argument $Argument | |
$TaskSetting = New-ScheduledTaskSettingsSet -Compatibility 'Win8' -ExecutionTimeLimit '00:05' -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -DontStopOnIdleEnd | |
$TaskTrigger = @((New-ScheduledTaskTrigger -AtLogOn), (New-ScheduledTaskTrigger -At '7am' -Daily)) | |
$TaskTrigger | Where-Object { $_.StartBoundry } | ForEach-Object { $_.StartBoundry = [DateTime]::Parse($_.StartBoundry).ToLocalTime().ToString('s') } | |
$Task = New-ScheduledTask -Action $TaskAction -Trigger $TaskTrigger -Settings $TaskSetting -Principal $Principal | |
$Task.Description = 'Scheduled task to run logon script at user logon and every day at 7am' | |
Register-ScheduledTask -InputObject $Task -TaskPath '\' -TaskName 'LogonScript' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment