Skip to content

Instantly share code, notes, and snippets.

@infamousjoeg
Last active January 27, 2022 17:15
Show Gist options
  • Save infamousjoeg/6a2a3377037c92c0a35ac9379fd0fb90 to your computer and use it in GitHub Desktop.
Save infamousjoeg/6a2a3377037c92c0a35ac9379fd0fb90 to your computer and use it in GitHub Desktop.
For directory monitoring and collection of XML files...
# VARIABLES
## XMLWatcher Variables
$XMLWatcher = New-Object System.IO.FileSystemWatcher
$XMLWatcher.Path = "C:\Program Files (x86)\CyberArk\PasswordManager\tmp"
$XMLWatcher.Filter = "*.xml"
# REGISTER PSJOB TO MONITOR FOR FILE SYSTEM CHANGES
Register-ObjectEvent $XMLWatcher -EventName Created -Action {
$datestamp = Get-Date -UFormat "%Y%m%d%H%M%S"
Write-Host "[${datestamp}] $($eventArgs.FullPath)"
Copy-Item $eventArgs.FullPath "C:\Windows\Temp\$datestamp.xml"
}
#Unregister-Event $object.Id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment