I want to monitor a specific folder for new created “Exchange Customer.csv”.
The monitoring works fine and in the console he writes “some text” BUT no Exchange2.csv file is being created.
If I start my script again, it writes 2 or 3 times “some text” in the console.
After having started the script for ± 4 times, it writes 6 times “some text” in the console AND creates the file Exchange2.csv.
Then it’s working all the time until I’m stopping it using:
Get-EventSubscriber | Unregister-Event
What am I doing wrong?
Here this part of the scipt
#watch folder and execute if new file has been added
$folder = $path
$filter = ‘Exchange Customer.csv’
$watcher = New-Object IO.FileSystemWatcher $folder, $filter
#Get Content, remove first 14lines
Get-Content $file| Select-Object -Skip 14 | Set-Content “$path\Exchange2.csv”
Write-Host “some text”
Register-ObjectEvent $watcher ‘Created’ -Action $action