我们希望监控服务器上其中一个共享文件夹上的文件活动。
$folder = 'D:\MySharedFolder'
计划使用FileSystemWatcher并记录New,Change&删除到文本文件。
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $true;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action
{
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green
Out-File -FilePath D:\Reports\Phx_New.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp"
}
我们希望在0800到1800(营业时间)之间运行监控
提前谢谢。