Exploring the Power of PowerShell: Simplifying File Search with Get-ChildItem

SQL Server DBA | Powershell |TSQL | Azure
In this article, we will delve into one of the most commonly used PowerShell cmdlets, Get-ChildItem, and explore how it simplifies file search operations. We will walk through a practical example of finding PNG files within a specific directory and its subdirectories, demonstrating the true power and elegance of PowerShell.
"Anecdote:"
A few months ago, during the Income Tax return season, I found myself in a bit of a predicament. I needed to submit a Rental document for claiming House Rent Allowance (HRA), but I couldn't locate the file amidst the multitude of folders and files on my computer. The conventional GUI search tools seemed inadequate as they only displayed the files but didn't provide an instant way to get the file's location, especially when dealing with a large number of files that matched the search pattern.
I promptly launched PowerShell and used the Get-ChildItem cmdlet with a specific filter to look for the rental document. The command I used was:
Get-ChildItem C:\Users\MyUsername\Documents -Recurse | Where-Object {$.Name -like "rental_document" -and $.Extension -eq ".pdf"} | ForEach-Object {$_.FullName} | Out-File 'C:\found_rental_document.txt'
Below is the screenshot of the PowerShell code that fetched the HRA document from Microsoft Onedrive in a short time.

