powershell - monitor for creation and then read a file via windows .bat script -
i write batch script poll windows directory time limit , pick file placed in directory. timeout after time if file not placed in directory within time frame.
i parse xml file , check status.
here's powershell script asked.
$content variable store contents of file (it array of lines can throw foreach loop).
$file = 'c:\flag.xml' $timeout = new-timespan -minutes 1 $sw = [diagnostics.stopwatch]::startnew() while ($sw.elapsed -lt $timeout) { if (test-path $file) { "$(get-date -f 'hh:mm:ss') found file: $file" $content = gc $file if ($content -contains 'something interesting') { "$(get-date -f 'hh:mm:ss') file has interesting in it!" } break } else { "$(get-date -f 'hh:mm:ss') still no file: $file" } start-sleep -seconds 5 }
Comments
Post a Comment