Hello
i have postet here an question and there mikrom posted a powershell solution to me.
So I'm moving this to here.
I would like to check several files, ideally from several PCs, for changes and then receive a notification.
after some googling I have this script
it works, only I always get two email's.
But i don't understand why
Can you tell me why?
And how can I query multiple paths ?!
Because I would like to be able to query several PCs
And when i edit the script to open a Picture, i get multiple E-Mails
I hope that someone here can explain or help me, why I get several emails here, although only one file changes.
And of course how I could check several PCs
Many Thanks
i have postet here an question and there mikrom posted a powershell solution to me.
So I'm moving this to here.
I would like to check several files, ideally from several PCs, for changes and then receive a notification.
after some googling I have this script
Code:
Add-Type -AssemblyName PresentationFramework
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "c:\tmp\tk"
$watcher.Filter = "*.cfg"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$null = Register-ObjectEvent $watcher "Changed" -Action {Send-MailMessage –To "Email.Adress@domain.com" –Subject "CFG DATEI GEÄNDERT!" –Body "CFG Datei wurde geändert!" –SmtpServer "smtp.com" –From "noreplay@domain.com" -encoding ([System.Text.Encoding]::UTF8)}
while ($true) {sleep 10}
it works, only I always get two email's.
But i don't understand why
Can you tell me why?
And how can I query multiple paths ?!
Because I would like to be able to query several PCs
And when i edit the script to open a Picture, i get multiple E-Mails
Code:
Add-Type -AssemblyName PresentationFramework
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "c:\tmp\tk"
$watcher.Filter = "*.cfg"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$null = Register-ObjectEvent $watcher "Changed" -Action {Send-MailMessage –To "Email.Adress@domain.com" –Subject "CFG DATEI GEÄNDERT!" –Body "CFG Datei wurde geändert!" –SmtpServer "smtp.com" –From "noreplay@domain.com" -encoding ([System.Text.Encoding]::UTF8)}
$null = Register-ObjectEvent $watcher "Changed" -Action {Invoke-Item "C:\Users\username\Documents\test.jpg"}
while ($true) {sleep 10}
I hope that someone here can explain or help me, why I get several emails here, although only one file changes.
And of course how I could check several PCs
Many Thanks