How to search files based on file extension using PowerShell

Опубликовано: 07 Апрель 2026
на канале: Fun & Tech
949
7

Shows how to search files based on extension in your drive, also shows how to search content of a txt file and replace it.

Search for 7z file extention in C drive
Get-ChildItem -Path c:\ -Include *.7z -File -Recurse -ErrorAction SilentlyContinue

Search for txt file in C drive
Get-ChildItem -Path c:\ -Include *.txt -File -Recurse -ErrorAction SilentlyContinue

Search multiple folders for 7z & txt extention files
Get-ChildItem -Path c:\NewFolder, C:\NewFolders -Include *.txt, *.7z -File -Recurse -ErrorAction SilentlyContinue

Search the content of a text file
Get-Content -Path 'C:\NewFolder\New Text Document.txt'

Replace the content of a text file
(Get-Content -Path 'C:\NewFolder\New Text Document.txt' -Raw) -replace 'This is a', 'My Test'

Replace the content of a text file and save it
(Get-Content -Path 'C:\NewFolder\New Text Document.txt' -Raw) -replace 'This is a', 'My Test' | Set-Content -Path 'C:\NewFolder\New Text Document.txt'