Last active
December 15, 2017 20:42
-
-
Save PCfromDCSnippets/970097988a3a9fd8483a82f2f5e9f094 to your computer and use it in GitHub Desktop.
Create Scheduled Task to Run As User
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
#region Create Scheduled Task as User | |
$jobName = "Azure S2S IP Checker" | |
$filePath = 'C:\Scripts\Update S2S and RRAS.ps1' | |
$cred = Get-Credential -Message "Enter Run As Credentials..." | |
$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 ` | |
-Credential $cred ` | |
-FilePath $filePath ` | |
-ScheduledJobOption (New-ScheduledJobOption -ContinueIfGoingOnBattery:$true -StartIfOnBattery:$true) ` | |
-Trigger (New-JobTrigger -Once -At "12/12/2017 01:00:00" -RepetitionInterval (New-TimeSpan -Hours 1) -RepeatIndefinitely) | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment