PowerShell: List files modified after xx and watch files
Kenichiro Nakamura
Posted on September 25, 2022
This is just a memo for myself.
List files modified after x seconds.
- Recurse: include subdirectories
- Force: include hidden files
- File: file only
Get-ChildItem -Recurse -Force -File | `
where LastWriteTime -gt (Get-Date).AddSeconds(-10) | `
select Name, LastWriteTime
Show tree structure of specified folder.
tree /F <folder>
Watch object creation and update of specified folder.
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "my files path"
$watcher.EnableRaisingEvents = $true
$watcher.IncludeSubdirectories = $true
$action = {
$fullPath = $event.SourceEventArgs.FullPath
$name = $event.SourceEventArgs.Name
$changeType = $event.SourceEventArgs.ChangeType
Write-Host "$changeType $name $path"
}
Register-ObjectEvent $watcher 'Changed' -Action $action
#Get-EventSubscriber | Unregister-Event
💖 💪 🙅 🚩
Kenichiro Nakamura
Posted on September 25, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
azure Securing Your Azure Cloud Environment with Application Security Groups (ASGs)
November 28, 2024