Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Monitoring file system changes in Powershell

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

# region Import Assemblies#- [void] [Reflection.Assembly]:: Load ("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void] [Reflection.Assembly]:: Load ("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") [void] [Reflection.Assembly]:: Load ("System.Drawing Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ") [void] [Reflection.Assembly]:: Load (" mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ") [void] [Reflection.Assembly]:: Load (" System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ") [void] [Reflection.Assembly]:: Load (" System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ") [void] [Reflection.Assembly]:: Load (" System.DirectoryServices, Version=2.0.0.0, Culture=neutral " PublicKeyToken=b03f5f7f11d50a3a ") # endregion Import Assemblies# sets the monitoring path $script:folder=" C:\ "$form=New-Object System.Windows.Forms.Form$form.FormBorderStyle=" Fixed3D "$form.StartPosition = 'CenterScreen'$form.ClientSize=" 200jie 80 "$form.Text=" Monitor "$buttonStart=New-Object System.Windows.Forms.Button$buttonStart.Text=" Start Watch "$buttonStart.Location=" 45 buttonStart.add_click ({start-watch}) $buttonStart.Size= "100J 20" $buttonStop=New-Object System.Windows.Forms.Button$buttonStop.Text= "Stop Watch" $buttonStop.Location= "45J 40" $buttonStop. Add_click ({stop-watch}) $buttonStop.Size= "100je 20" $form.Controls.AddRange (@ ($buttonStart) $buttonStop) $script:watcher = New-Object System.IO.FileSystemWatcher $folder# starts monitoring function start-watch {$NotifyFilters=New-Object System.IO.NotifyFilters # $watcher.NotifyFilter= "Size,LastWrite,LastAccess,CreationTime,Security" $watcher.Filter = "*. *" $watcher.InternalBufferSize = 65536 # whether it contains subdirectories $watcher.IncludeSubDirectories = $True # whether events are triggered You must enable $watcher.EnableRaisingEvents = $True $watcher.SynchronizingObject = $form $form.Text= "Monitoring" $buttonStart.Enabled=$false # trigger $watcher.add_Created ({created}) $watcher.add_Changed ({changed}) $watcher.add_Deleted ({deleted}) $watcher.add_Renamed ({renamed})} function msg ($message) {[Windows.Forms.MessageBox]:: Show ($message)} # $_ .changetype get operation type # $_ .fullpath get file absolute path function created () {# create file # write processing logic msg ($_ .fullpath)} function changed () {# file information change # write processing logic msg ($_ .fullpath)} function deleted () {# delete file # write processing logic msg ($_ .fullpath)} function renamed () { # name change # write the processing logic msg ($_ .fullpath)} # stop monitoring function stop-watch {$watcher.EnableRaisingEvents = $false $form.Text= "Monitor" $buttonStart.Enabled=$true} $form.ShowDialog ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report