Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Created July 2, 2014 21:41
Show Gist options
  • Save pcgeek86/b5f29ab8a11b414b230f to your computer and use it in GitHub Desktop.
Save pcgeek86/b5f29ab8a11b414b230f to your computer and use it in GitHub Desktop.
$MyFilter = New-WmiEventFilter –Name WatchFolderRoboCopy –Query 'SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA "CIM_DirectoryContainsFile" AND TargetInstance.GroupComponent = "Win32_Directory.Name=\"c:\\\\FileHistory\""' –EventNamespace "root\cimv2"
$MyConsumer = New-WmiEventConsumer –ConsumerType CommandLine –Name WatchFolderRoboCopy –CommandLineTemplate "c:\\windows\\system32\\windowspowershell\\v1.0\\powershell.exe -ExecutionPolicy Bypass -<<<ParameterName1>>> %TargetInstance.<<<WmiPropertyName>>>%"
New-WmiFilterToConsumerBinding –Filter $MyFilter –Consumer $MyConsumer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment