I'm trying to schedule a task that runs a PS script with parameters. But I believe I'm missing an escape character somewhere or my ' and " are in the wrong place. I can't seem to get it to work properly without it splitting the action argument. Below is my code:
$employeeID = "1234"
$employee = "email@email.com"
$restoretime = (Get-date).AddHours(12)
$restoreuser = "$($employee) Offboarding"
$trigger = New-ScheduledTaskTrigger -once -At $restoretime
$taskAction = New-ScheduledTaskAction -Execute '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe' -Argument `
-Command "& 'C:\Location\testing.ps1' -employeeID '$($employeeID)' -employee '$($employee)'"
Register-ScheduledTask -TaskName $restoreuser -Action $taskAction -Trigger $trigger
Any help would be appreciated!
I've tried the approaches here with no luck!