Search-Files.ps1
<#PSScriptInfo .VERSION 1.2 .GUID e21001d0-93f4-4d25-b01d-1dca9e0bc4a6 .AUTHOR ddochea .COMPANYNAME .COPYRIGHT .TAGS Search, Files, Word .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES add encoding parameter .PRIVATEDATA #> <# .DESCRIPTION File containing search word #> # Parameter help description Param( [Parameter(Mandatory=$true, HelpMessage="Path to search for files")] [String]$Path, [Parameter(Mandatory=$true, HelpMessage="Word to search for")] [String]$Word, [Parameter(Mandatory=$false, HelpMessage="Encoding of the file")] [String]$Encoding = "utf8" ) Get-ChildItem $Path -Recurse | ForEach-Object { if($_.GetType().Name -eq "FileInfo") { $fileContent = Get-Content $_.FullName -Encoding $Encoding if($fileContent -match $Word) { Write-Host "File containing search word '$Word': $($_.FullName)" } } } |