I'm trying to run a command that will add a scheduled task that will run a PowerShell command.
Schtasks /create /tn "Give Tom access to Bob" /sc once /st 20:00 /tr "PowerShell -command Add-ADPermission -Identity "Bob Jones" -User "Tom Smith" -AccessRights ExtendedRight -ExtendedRights "send as" -ErrorAction Stop; Add-MailboxPermission "Bob Jones" -User "Tom Smith" -Access "FullAccess" -confirm: $false -ErrorAction Stop"
This is what I'm trying to do up there:
Run 2 commands at the specified time (once, 8:00)
But I'm running into an issue, I think, with the quotes.
I'd get the error:
ERROR: Invalid argument/option - 'Bob'.
Is this a quote issue?
Also will the ; help with running both commands within the task?
Or is the best way here to generate the commands to run into a ps1 file and then have the ps1 file run? And if so, could I add a command to delete the ps1 (itself) after its run?