im trying to create a scheduled Task for the currently Logged On User
##Create task for a backup of the Notes on drive Y:\
# Defining the task parameters
$taskName = "StickyNotesBackup"
$TaskDescription = "Backup of the Sticky Notes database daily at 4 a.m."
$actionPath = "robocopy.exe"
$actionArguments = "`"C:\StickyNotesDB`" `"Y:\Simple Sticky Notes\Backup`" Notes.db /XO /W:5 /R:2"
$hidden = $true
# Check whether the task planning module is loaded and load it if necessary
if (-not (Get-Module -ListAvailable -Name TaskScheduler)) {
Import-Module TaskScheduler
}
# Create the triggers for daily execution at 4 a.m.
$triggerDaily = New-ScheduledTaskTrigger -Daily -At "4:00am"
# Creating the task action
$action = New-ScheduledTaskAction -Execute $actionPath -Argument $actionArguments
# Configuring the task for the current user
$taskUser = "$env:USERDOMAIN\$env:USERNAME"
$taskPrincipal = New-ScheduledTaskPrincipal -UserId $taskUser -LogonType S4U
$taskSettings = New-ScheduledTaskSettingsSet -Hidden -RunOnlyIfIdle:$false -DontStopIfGoingOnBatteries:$false -StartWhenAvailable:$true -DontStopOnIdleEnd:$false
# Creating the task
Register-ScheduledTask -TaskName $taskName -Description $TaskDescription -Action $action -Trigger $triggerDaily -Principal $taskPrincipal -Settings $taskSettings
If i run this Part of my Deployment Script locally (run Deploy-Application.exe) it works fine, if i run it by using SCCM the task is not created. i´m pretty sure its because SCCM Installation uses the SYSTEM Account to perform its Actions.
Would be anyone of you that nice to help me to run that script using SCCM?