In the code below there is a parameter named "$action" = {...}. Inside the brackets there are some variables ($path, $logPath, etc.) How can I access variables from this parameter outside of the braces "{}"? I need result of one of my functions("RunFunctions") for a while loop. Or if it's some stupid question please can you point me to the place where I can find some information about this {} notation? Thanks.
try {
### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\Testers\ResetOptimisation\tracking"
$watcher.Filter = "user_name*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = { $path = $Event.SourceEventArgs.FullPath
$logPath = "C:\Testers\ResetOptimisation\output\log.txt"
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content $logPath -value $logline
$terminateFlag = RunFunctions $path $changeType $logPath
}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
Register-ObjectEvent $watcher "Changed" -Action $action
Register-ObjectEvent $watcher "Deleted" -Action $action
Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true) {
Write-Host $teminateFlag
if ($teminateFlag -eq 1) {
Exit
}
Start-Sleep 3
}
}
catch {
Write-Host $_
}