我想知道是否有人可能知道一种方式,我可以在Windows Server 2012中的目录中设置自动生成文件更改日志。我们有一个word,excell和pdf文件的集合,我目前必须手动创build一个更改日志每周一次。 我想知道是否有可能让窗户处理这个过程。 任何帮助或指导将不胜感激。
使用WMI。 这里是一个vbscript版本,解释如何使用CIM_DirectoryContainsFile中的__InstanceOperationEvent
http://www.codeproject.com/Articles/42212/WMI-and-File-System-Monitoring
这可能会在2008年缓慢,但似乎在2012年运行文件
另一种select是使用filewatcher:
Write-Verbose ("Initializing FileSystemWatcher") -Verbose $fileWatcher = New-Object System.IO.FileSystemWatcher $fileWatcher.Path = "C:\folder" Register-ObjectEvent -InputObject $fileWatcher -EventName Created -SourceIdentifier File.Created -Action { $Global:t = $event Write-Host ("File/Folder Created: {0} on {1}" -f ` $event.SourceEventArgs.Name, (Split-Path $event.SourceEventArgs.FullPath)) -BackgroundColor Black -ForegroundColor Red } | Out-Null Register-ObjectEvent -InputObject $fileWatcher -EventName Deleted -SourceIdentifier File.Deleted -Action { $Global:t = $event Write-Host ("File/Folder Deleted: {0} on {1}" -f ` $event.SourceEventArgs.Name, (Split-Path $event.SourceEventArgs.FullPath)) -BackgroundColor Black -ForegroundColor Red } | Out-Null Register-ObjectEvent -InputObject $fileWatcher -EventName Changed -SourceIdentifier File.Changed -Action { $Global:t = $event Write-Host ("File/Folder Changed: {0} on {1}" -f ` $event.SourceEventArgs.Name, (Split-Path $event.SourceEventArgs.FullPath)) -BackgroundColor Black -ForegroundColor Red } | Out-Null
我推荐Jim B的解决scheme与WMI,但如果你想要更简单的PowerShell的:
Dir C:\folder -r | ? {! $_.PSIsContainer -AND $_.lastwritetime -ge '04/18/14'} > changed.txt
这将自04/18/14创build一个名为changed.txt的文件,每个文件在c:\folder (及其子目录)中都被04/18/14 。
(学分:我在这里从用户nixda得到这个)
您可以将此脚本添加到您的任务计划程序以每天运行。
我不知道有什么方法来获取哪个用户更改文件的信息。 它可以在VBA中的Word和Excel文件中完成。