Cmdlet-based filtering restricts results through a cmdlet's own parameters before downstream processing. In a file watcher, this keeps the watcher focused on finding only the files it needs and leaves heavier actions to a separate action script. section 3.3.1
Filter XML files with Get-ChildItem
Get-ChildItem -Filter '*.xml' limits the returned items to XML files. This avoids returning every item and filtering afterward with Where-Object, reducing watcher runtime. section 3.3.1
Apply the technique alongside scoped watcher design:
- Use cmdlet parameters instead of Where-Object whenever the cmdlet provides an equivalent filter. section 3.3.1
- Scope commands to the specific folders or organizational units required rather than relying on broad recursive searches. section 3.3.1
