Use o WMI. Aqui está uma versão vbscript explicando como usar __InstanceOperationEvent de CIM_DirectoryContainsFile
Isso pode ser lento em 2008, mas parece executar o arquivo em 2012
Outra opção é usar o 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