Domanda

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!

È stato utile?

Soluzione 2

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.

Altri suggerimenti

I have not been able to get FileSystemWatcher to work unless the target directory was a Windows NTFS drive. If I specify the drive letter of the mapped directory I get

Exception setting "Path": "The directory name W:\ is invalid."

If I use the UNC I get

Exception calling "WaitForChanged" with "2" argument(s): "Error reading the \\\\path.to.my.ibm.i\\root\ directory."

Against a Novell file server I get the directory name is invalid if I use a drive letter. If I use a UNC against a Novell drive it does run, but doesn't detect any changes to the file system. Works fine against a local drive and also against a Windows file server on my network.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top