Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Run a Powershell script during system restart

$
0
0

Hi, 

I'm having the following Powershell script to monitor for a File creation event:

$folder = 'D:\LoadTesting2'

$filter = 'runTest.bat'

$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}

Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action { Start-process D:\LoadTesting2\runTest.bat}

I want this Powershell script to execute during system startup itself. Where do I place this file so that it starts monitoring for the file creation event as soon as the system gets started, any execution policies needs to be added? Also, I want to place this script to that corresponding folder remotely as well through Powershell. Is that possible?

I tried placing this script in "C:\Documents and Settings\saravind\Start Menu\Programs\Startup" but as soon as the system starts up, Powershell script opens up in a notepad. :(

Thanks in advance

-Aravind




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>