June 2025
Beginner to intermediate
473 pages
13h 30m
English
To search for files that have certain properties, you can proceed as in the previous example: Create a result list via Get-ChildItem and then use Where-Object to select the objects that match your expectations. The condition must be formulated in curly brackets. Within this formulation, $_ refers to the object currently being processed.
In the following listing, we first create a variable that contains the date from 60 days ago. Get-ChildItem searches the current directory and all subdirectories for all *.pdf files. Where-Object, which can be abbreviated quite elegantly with ?, filters out the PDF documents that were created or modified in the last 2 months. (-ge stands for greater than or equal to.)
> $twoMonthsAgo = (Get-Date).AddDays(-60) ...
Read now
Unlock full access