I'm trying to set up a scheduled task that runs under the user's credentials, but I'm hitting a snag with a syntax error. It seems like the issue lies with my $Principal setting. I attempted to use both 'NT AuthorityInteractive' and 'BUILTINUsers', but I keep getting the error: "Register-ScheduledTask : No mapping between account names and security IDs was done." What am I doing wrong, and how can I fix this? Here's the code I've been working with:
```powershell
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:ScriptsMyScript.ps1"
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 1)
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Minutes 10)
$Principal = New-ScheduledTaskPrincipal -UserId "'BUILTIN\Users'" -LogonType Interactive
Register-ScheduledTask -TaskName "MyDailyTask" -Action $Action -Trigger $Trigger -Principal $Principal -Settings $settings
```
Thanks for the help!
3 Answers
Have you considered using the SID for the user group? Something like `$principal = New-ScheduledTaskPrincipal -GroupId "S-1-5-32-545" -Id "R/Powershell" -RunLevel Highest` might work for you! Give that a shot!
Just a heads up, to achieve what you're trying to do, you'll need the user's actual credentials. Neither of the options you've chosen ('NT AuthorityInteractive' or 'BUILTINUsers') qualify as valid user accounts for this kind of setup.
You might want to try using Schtasks.exe instead. It can create tasks that run as the current user without needing to pass any credentials, which could save you some trouble!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically