I found this insanely easy, thanks to some well written Microsoft documentation (shocking I know). If you need to create a scheduled task of an application in your PowerShell script you can call the Schtasks.exe application. Below is an example I used to create a scheduled task to run my exe every day at 1:00a.m. using the System account:
Write-Host “Creating Account Collector Scheduled Task”
Schtasks /create /sc DAILY /tn AccountCollector /tr “`”`”`”`”C:\Program Files\AMF\AMFCollector.exe`”`”`”`”” /s devsbvm01 /ru System /st 01:00:00
Write-Host “Scheduled Task Created”
That’s it, works painlessly on a local or remote server, which in my example, devsbvm01 is my remote server. Now, you might be wondering “whats with all the quotes?”. Well, I struggled for a long time trying to figure out why the scheduled task would be created but would never run. Turns out that the qoutes were being stripped out, thus causing the path to break. I know its sleazy, but turns out you need four sets of quotes in order to keep them from being stripped out! If anyone ever finds a better way, let me know but this seems to be it for now! So make sure you put those quotes in there!