Hi,
If you want the script works on both windows server 2012 and 2016, you could use different parameters based on the os version.
$starttime=(get-date)
$Params2012 = @{
"Once" = $true
"At" = $startTime
"RepetitionInterval" = (New-TimeSpan -Minutes 3)
"RepetitionDuration" = ([TimeSpan]::MaxValue)
}
$Params2016 = @{
"Once" = $true
"At" = $startTime
"RepetitionInterval" = (New-TimeSpan -Minutes 3)
}
if([environment]::OSVersion.Version.Major -eq 10){$Params = $Params2016}
if([environment]::OSVersion.Version.Major -eq 6){$Params = $Params2012}
$trigger = New-ScheduledTaskTrigger @Params
Best Regards,
Ian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.