user10675448
user10675448

Reputation: 33

Running Windows Powershell script always from task scheduler

This might be a very basic question. I have FileWatcher script in windows powershell which I want to run always so that it keeps watching a particular location for files. when I run it from Windows Powershell IDE its run perfectly fine. I understand that I can schedule a task in windows task scheduler for that but what's happening is that the task runs and then comes back in "Ready" status. This is NOT working. I think it should be in "Running" state always. I might be missing something. Please kindly help with your valuable suggestions.

Upvotes: 0

Views: 1771

Answers (1)

postanote
postanote

Reputation: 16096

You can do this with TaskSchedule…

Running PowerShell scripts as a “service” (Events: Prologue)

but this is also what permanent Event Subscriptions are for or setting up as user10675448 suggest, make it a real service.

How to run a PowerShell script as a Windows service

Windows PowerShell - Writing Windows Services in PowerShell

This article presents the end result of that effort: A novel and easy way to create Windows Services, by writing them in the Windows PowerShell scripting language. No more compilation, just a quick edit/test cycle that can be done on any system, not just the developer’s own.

There is also this approach...

PowerShell and Events: Permanent WMI Event Subscriptions

Unlike the temporary event, the permanent event is persistent object that will last through a reboot and continue to operate until it has been removed from the WMI repository.

There are multiple ways of setting up the WMI events and I will be covering 3 of those ways (as they deal with PowerShell) in this article.

Upvotes: 0

Related Questions