I need a FileWatcher script to detect new files and execute another powershell script if the files are found. The destination directory of this 2nd PS script outputs file to a UNC mount that has the directory mounted as P: . That UNC mount is actually a SMB share from a Linux machine. That Linux machine hosts a SMB service with access granted to one linux user on the box. That linux user has the proper rights to create and modify the files within the SMB directory.
I can get the filewatcher script to perform the actions perfectly fine if I run the script in a live window while I am logged in.
I cannot get the filewatcher script to run as a windows service and properly execute a command after the System.IO.FileSystemWatcher detects a new file.
I used the winsw.exe format to create the Windows Service. When I run this as the SYSTEM user...nothing. When I run the service as myself, the same user that successfully runs it in a live window, nothing.
Here is the winsw.xml
<service> <id>StartWatchingFiles</id> <name>Start Watching Files</name> <description>This is used to watch files.</description> <executable>PowerShell.exe</executable> <logmode>reset</logmode> <arguments>-ExecutionPolicy Bypass -File "C:\scripts\StartWatching.ps1"</arguments> </service>
After this runs, the files are generated and the watcher script will not fire off the PS script in response to that newly detected file.