Windows IOT task not run on startup (but it runs on manual command) - scheduled-tasks

I created a .bat file which execute .ps1 file.
Then I added scheduled tasks:
schtasks /Create /SC ONSTART /TN MyApp /TR "c:\Projects\MyApp\Startup.bat" /RU SYSTEM
and power down Raspberry Pi 3B+. When I supply power again, my ASP.NET Core 3.0 app is not running.
If I connect to Raspberry Pi power shell and run
schtasks /Run /TN MyApp
application runs (web page is displayed).
Is there any logs, where I could found what went wrong?
Has anybody have any idea, why task is not ran on application start up?
Every post I found mention that task also doesn't run/execute if tried manually. But this is not my case.

You can use ETW on Windows IoT Core to trace the event log for schedule tasks. The Microsoft-Windows-TaskScheduler provider can be used to track the detail info when a scheduled task run or stop.
BTW, I'm not sure what's the content in your Startup.bat and *.ps1 file. I created the files with following content, it works for me.
Startup.bat
#echo off
powershell -executionpolicy bypass -File "C:\Projects\MyApp\start.ps1"
start.ps1
Start-Process -NoNewWindow -FilePath "C:\Projects\MyApp\NetCoreWebApp.exe"
Before you created the scheduled task, you can test the scripts step by step to ensure the script works fine.

Related

Powershell Script to create Scheduled Task on non domain computers

We are trying to execute a powershell script that will import a scheduled task to non domain and domain joined computers in our organization. The task is simply to disable wifi adapter when an ethernet cable is connected. I exported the task as a .xml and then can get the task to run as admin and complete successfully. However when we attempt to run logged in as normal user, the UAC box pops up asking for admin username and password. I created the task as both domain admin and local admin accounts and tried both, with same result when running the .bat as normal user.
This is my script so far (I have no previous experience in writing powershell):
Copy-Item -Path D:\WiFi -Destination C:\PCM\Utils -Recurse;
schtasks /create /tn "Ethernet On-Disable Wifi" /xml "C:\PCM\Utils\WiFi\Ethernet On-Disable Wifi.xml" /ru Domain\admin /rp domainpw;
schtasks /create /tn "Ethernet Off-Enable Wifi" /xml "C:\PCM\Utils\WiFi\Ethernet Off-Enable Wifi.xml" /ru Domain\admin /rp domainpw;
*
I'd like to be able to run this as %computername%\localadmin as that account is on all laptops...
The first line copies a folder with the .xml from a thumb drive to a folder on laptop. Then it creates the tasks. If I am logged into the laptop as admin, the batch runs fine, but as a local user, it fails with the following:
Error Image
Basically, it copies the folder fine, then ERROR: Access is denied.
I'm pretty sure its because the user logged in does not have rights to create the task. Is there a way to have the task run as localadmin and complete?
We run this .bat file to fire off the .ps1 from the folder that gets copied to laptop.
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'D:\WifiTask\WifiTask.ps1'"
pause
Sorry if the description of this issue is vague or confusing, just trying to learn as I go....thanks
No, a normal user will not be able to create a system scheduled task without getting prompted for elevation by UAC.
For domain computers, you could try:
Group policy to create the scheduled task
Group policy to run your script as the local system user
Script that connects to computers as Admin user and pushes your xml and wifitask.ps1 like Invoke-Command
Off-domain PCs are more difficult, you would want to do it the same way you currently install other software. Manually run as-admin? Software deployment agent? Remote management tools?

How to deploy .exe to scheduler task using Powershell script

I developed a console app and scheduled it to run on Mon-Friday at 9:AM using windows task scheduler, it works fine.
But I was asked to write Powershell scripts or command-line scripts for deployment, like the script should copy the "Release" folder to the server1(deployment env like dev, test or staging or prod) and schedule it in server1's schedule task. Also I have to set "Start in(optional)".
I don't know anything about command-line and PS scripts. All it should do is create the windows schedule task just like the way I did using UI.
If I understand the question correctly you're just trying to create a scheduled task using powershell?
If so try starting here:
https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/13/use-powershell-to-create-scheduled-tasks/
I had a requirement to schedule an exe, this scheduled task should run every day Mon to Fri at desired time. I never wrote any batch files in last 15 years of my career :), took it up as it came in my way from my manager. Thanks to him or else I would have not known in this new world.
echo off
title My 1st batch file for Task scheduler
SchTasks /Create /RU "system" /Sc WEEKLY /D MON,TUE,WED,THU,FRI /TN "Leads" /TR "C:/Some.exe" /ST 09:00

Scheduled powershell script run by system does not run in foreground

I am trying to schedule a script to run when I'm not present at my computer. The script has to run with administrator rights AND run in the foreground so that I can see any message or window that is created when I get back to the computer.
The problem is that scheduled system scripts run in the background, this resulting in no visible window or console to show me any results.
here is the command i use to create my scheduled task (using powershell):
SchTasks /Create /SC ONIDLE /I 1 /TN MyScheduledTask /TR "Powershell scheduler.ps1" /RU "System"
All I need is some way to make some (or all if that's easier) of the commands in the script to become visible in the foreground to the user.
Thanks for any feedback.
When running scheduled tasks under the system account, they will run in the background.
You are running the task under System, /RU "System" use /RU with your username and /RP for your user password.
Please also take a look at this question: Powershell Task Scheduler Stuck Running

How to configure selenium webdriver script and powershell script to run once in a week

I have one selenium webdriver script and another powershell script.
I want to configure both scripts to run on each thursday at 6 pm. How to achieve that.
Create a Windows Scheduled task to run a PowerShell script.
Here is the step by step guide on how to do that.
Use-the-windows-task-scheduler-to-run-a-windows-powershell-script
Then just schedule the script according to your timelines.
If you want to configure the scheduled task also using PS, then here is my blog to help you out on that.
PS Scheduled Task Script
Alternative,
Creation of Task Scheduler Script using cmdlets:
powershell create scheduled-tasks
Hope it helps.
Not sure about Selenium (don't know what that is), but PowerShell scripts can be scheduled using the regular Windows Task Scheduler.
Scheduled tasks can be manually created using the Windows Task Scheduler (taskschd.msc), or via the command-line using schtasks.exe, e.g.:
schtasks.exe /Create /sc weekly /d THU /st 18:00 /tn MyPowerShellJob /tr "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -file d:\MyScript.ps1 \"hello world\" foo" /ru JohnDoe /rp

IoT Core 14393 - FTP Schtask not executing upon boot

I have successfully upgraded our DragonBoards 410c to IoT core build 14393.
As stated in the MS release notes
https://developer.microsoft.com/en-us/windows/iot/docs/releasenotesinsiderpreview
the FTP server is no longer loaded by default at startup.
I have tried to create a scheduler task as follows:
schtasks /create /tn IoTFTPD /tr ftpd.exe /ru system /sc onstart
The task was created successfully via PowerShell. The task can be executed manually via Powershell:
schtasks /run /tn IoTFTPD (it will start the ftp server).
The problem is that the task does not execute upon startup of the device.
Any help is greatly appreciated.