Is this even possible?
I want to use MS Endpoint/Intune to run a powershell script that creates a scheduled task on a Windows 10 machine.
The script I run is:
$taskName = "Task-Name"
$action = New-ScheduledTaskAction -Execute "Rundll32.exe" -Argument "user32.dll,LockWorkStation"
$trigger = New-ScheduledTaskTrigger -Daily -AT "23:00"
$settings = New-ScheduledTaskSettingsSet
$inputObject = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings
Register-ScheduledTask -TaskName $taskName -InputObject $inputObject
The task will lock the machine at a specific time.
When I paste the script contents into a local powershell, the scheduled task is created.
When I use Endpoint to push the script to a remote machine, it fails.
The Sensor log file on the remote machine reports:
<![LOG[[LogonTaskHelper] Cannot remove task from task scheduler... It does not exists.]LOG]!
The spelling of exists is correct!
Remote Windows 10 is Version 20H2
Am I trying to achieve the impossible?
Cheers