0
votes

I'm trying to monitor files appearing in an azure file share using the FileSystemWatcher in PowerShell. The script works correctly when looking at folders on the machine, but when I point it to look at a mapped rive that has been mapped to azure File share it reports "The directory name is invalid.

New-Object : Exception calling ".ctor" with "2" argument(s): "The directory name is invalid."

The mapped drive appears in explorer and can be accessed. Can FileSystemWatcher access azure resources?

1
By FileSystemWatcher are you referring to this gallery.technet.microsoft.com/scriptcenter/…Satya V

1 Answers

0
votes

FileSystemWatcher works well with monitoring mounted Azure File Shares as well.

You would just have to mount the file share correctly and assign it a Drive letter. For example, I have an active file share mounted as Drive Z:\ on my machine.

Once mapped, set the folder and filter variables:

$folder = 'Z:\' # Or the drive letter you have the share mounted onto
$filter = '*.*'

# Create an instance of the FileSystemWatcher class
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'} 

The rest of the script can be executed as is. Here is how it would look:

FileSystemWatcher