I'm using the following powershell script to monitor new files coming in an IBM iSeries shared folder.
# variables
#$folder = "\\10.10.0.120\transform\BE\FORM"
#$folder = "C:\Users\Administrator.ALI\Desktop\AS400"
#$folder = "\\nb091002\Temp"
$folder = "I:\"
$filter = "*.txt"
$aswform = "C:\ASWFORM\aswform.exe"
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $folder
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $false
$watcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite -bor [System.IO.NotifyFilters]::FileName
while($TRUE){
$result = $watcher.WaitForChanged([System.IO.WatcherChangeTypes]::Changed -bor [System.IO.WatcherChangeTypes]::Renamed -bOr [System.IO.WatcherChangeTypes]::Created, 2000);
if($result.TimedOut){
continue;
}
Write-Host $result.Name
#$aswform $folder
}
This seems to work fine on local folders or domain shares.
I've tried mapping the iSeries shared folder to a network drive but it doesn't work.
(10.10.0.120 is the AS400)
I'm pretty sure it has to do something with credentials....
Strange thing is I can access the shared folder from within Windows perfectly.
Does anybody have any clues or tips for me?
PS: little detail, I'll be running this script through task sheduler with this trigger
powershell -NoExit -WindowStyle Hidden -File "C:\ASWFORM\watcher.ps1"
But first I need it working when running the script manually!
I solved the problem by writing a small C# console application to poll the folder
instead of using the .Net FileSystemWatcher object.
I manually (instsrv.exe) installed this program as a service and it seems to be running ok.
If you want the code, please send me a PM and I'll see to it that you get it.