TDLR: use Windows task scheduler.
When an Azure DevOps agent is installed on a server, you get to choose which account the service runs as, however, there might be cases when you would like the agent to run a script or program on a server as another Windows user than the agent is configured with.
I recently wanted to automate the transfer of a database backup via a DevOps release pipeline, the task was automated with a PowerShell script, but the script needed to run as a service account that had specific permissions. Running the agent as the service account was not an option. The server did neither have WinRM nor PowerShell Remoting enabled, which you can use to remotely run a script as another user.
One possible solution mentioned on stack overflow is to set up a PowerShell script on the server which includes the credentials of the service account and with that script launch another process of PowerShell to run the final script. With that approach, there was no easy way to get DevOps to show the task as running and report back errors.
In the end, I set up a task in Windows Task Scheduler on the server that runs as the service account and executes the PowerShell script locally, the DevOps release pipeline starts the task via PowerShell.

The following PowerShell script was used in Azure DevOps to start that task, it shows the task as running, and reports back unsuccessful runs.
$taskName = "Create Database Backup"
Start-ScheduledTask -TaskName $taskName
while ((Get-ScheduledTask -TaskName $taskName).State -eq 'Running') { Write-Verbose -Message "Running task..." }
$taskResult = (Get-ScheduledTaskInfo -TaskName $taskName).LastTaskResult
If($taskResult -ne 0) { throw "Task was not completed successfully." }
