Created
April 4, 2017 01:42
-
-
Save PCfromDCSnippets/2d064c0e1f06a5cc63007e30ff004f23 to your computer and use it in GitHub Desktop.
Create Log In Task
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
#region Create Log In Task | |
$user = whoami | |
$sj = Get-ScheduledJob -Name $jobName -ErrorAction SilentlyContinue | |
if ($sj.count -gt 0) { | |
Write-Host "$jobName scheduled job already exists..." | |
} | |
else { | |
Write-Host "Creating $jobName scheduled Job..." | |
$sj = Register-ScheduledJob –Name $jobName ` | |
-ScriptBlock $sb ` | |
-ScheduledJobOption (New-ScheduledJobOption -ContinueIfGoingOnBattery:$true -StartIfOnBattery:$true) ` | |
-Trigger (New-JobTrigger -AtLogOn -User $user) | |
} | |
Write-Host "Updating $jobName scheduled task..." | |
$path = (Get-ScheduledTask $jobName).TaskPath | |
$principal = New-ScheduledTaskPrincipal -UserId $user | |
$st = Set-ScheduledTask -TaskName $jobName -Principal $principal -TaskPath $path | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment