Using PowerShell for automatic email notification on file changes
suppose have shared folder called ourfiles getting updated time-to-time new files , subfolders. there way use powershell to:
1. run command output list to see files in folder were: a. added, b. updated/modified, or c. deleted in past day (or past hour or past minute, or whatever)?
2. take output of command , redirect text file
3. or (preferred) take the output of command , send email output body of message?
am asking of powershell, or that's pretty doable?
here's started:
$fsw = new-object system.io.filesystemwatcher d:\scripts
$fsw.enableraisingevents=$true
$fsw.includesubdirectories=$false
register-objectevent -inputobject $fsw -eventname created -sourceidentifier createdevent -action {
write-host "$($eventargs | format-list | out-string)"
}
register-objectevent -inputobject $fsw -eventname changed -sourceidentifier changedevent -action {
write-host "$($eventargs | format-list | out-string)"
}
register-objectevent -inputobject $fsw -eventname deleted -sourceidentifier deletedevent -action {
write-host "$($eventargs | format-list | out-string)"
}
register-objectevent -inputobject $fsw -eventname renamed -sourceidentifier renamedevent -action {
write-host "$($eventargs | format-list | out-string)"
}
shay levy [mvp]
powershay.com
powershell toolbar
Windows Server > Windows PowerShell
Comments
Post a Comment