Searching for files

In this recipe, we will search for files based on filenames, attributes, and content.

How to do it...

Let's explore different ways to use Get-ChildItem to search for files:

  1. Open PowerShell ISE as an administrator.
  2. Add the following script and run it:
    #search for file with specific extension $path = "C:\Temp" Get-ChildItem -Path $path -Include *.sql -Recurse #search for file based on date creation #use LastWriteTime for date modification [datetime]$startDate = "2015-05-01" [datetime]$endDate = "2015-05-24" #note date is at 12 midnight #sample date Sunday, May 24, 2015 12:00:00 AM #search for the file Get-ChildItem -Path $path -Recurse | Where-Object CreationTime -ge $startDate | Where-Object CreationTime -le $endDate | Sort-Object ...

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.