How to deploy .exe to scheduler task using Powershell script - powershell

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

Related

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

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.

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.

Programmatically Creating a Scheduled Task in Windows - 0x8004130f Error

I am having major problems getting a scheduled task to run. The task is created fine using the ITaskScheduler interface provided by Microsoft. The task is set to run only if a user is logged on.
The problem is that the task does NOT run and the log file SchedLgU.txt cites the reason as being:
"The attempt to retrieve account information for the specified task failed; therefore, the task did not run. Either an error occurred, or no account information existed for the task.
The specific error is:
0x8004130f: No account information could be found in the Task Scheduler security database for the task indicated."
I know for a fact that a scheduled task can be created with no account information because the Google Updater scheduled task does this, and it runs fine.
All I can gather from web searches is that Windows has a "scheduled task database" that needs to have credential information for each task for it to be able to run.
Does anyone know how to modify this credential database or any other way to get my task to run?
The GoogleUpdateTaskMachine Task uses the "NT AUTHORITY\SYSTEM" to Run the task. You can do this by using schtasks command and the /ru switch with "System" or "" as the parameter. Like this:
schtasks /create /tn "My App" /tr c:\apps\myapp.exe /sc monthly /d 15 /ru "System"
It does not prompt for a password.
See technet for more info.
you could use batch scripting.
schtasks /create /tn UNO /tr YOURAPP.EXE /sc HOURLY /mo 2
there you go.
read: How to use Schtasks.exe to Schedule Tasks in Windows Server 2003
As far as I know, and the documentation backs this up, an account is required for a scheduled task. If you set the task to run only when a user is logged in that only means a password is not necessary, you still need an account. This account can be set to a group so that the task will be run when it is triggered as long as anyone in the group is logged on. For instance you can set the account to 'Users' so that the task can run when anyone is logged on.