diff --git a/Data/scripts.csv b/Data/scripts.csv index b88be999..fb567f14 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -122,6 +122,7 @@ new-email.ps1, starts the default email client to write a new email reboot.ps1, reboots the local computer (requires admin rights) reboot-fritzbox.ps1, reboots the FRITZ!box device remove-empty-dirs.ps1, removes empty subfolders within the given directory tree +search-filename.ps1, searches the directory tree for filenames by given pattern search-files.ps1, searches the given pattern in the given files scan-ports.ps1, scans the network for open/closed ports send-email.ps1, sends an email message diff --git a/README.md b/README.md index 6e5095a8..d686ad59 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Mega Collection of PowerShell Scripts * [make-install.ps1](Scripts/make-install.ps1) - installs built executables and libs to the installation directory * [MD5.ps1](Scripts/MD5.ps1) - prints the MD5 checksum of the given file * [remove-empty-dirs.ps1](Scripts/remove-empty-dirs.ps1) - removes empty subfolders within the given directory tree +* [search-filename.ps1](Scripts/search-filename.ps1) - searches the directory tree for filenames by given pattern * [search-files.ps1](Scripts/search-files.ps1) - searches the given pattern in the given files * [SHA1.ps1](Scripts/SHA1.ps1) - prints the SHA1 checksum of the given file * [SHA256.ps1](Scripts/SHA256.ps1) - prints the SHA256 checksum of the given file diff --git a/Scripts/search-filename.ps1 b/Scripts/search-filename.ps1 new file mode 100644 index 00000000..226dd76b --- /dev/null +++ b/Scripts/search-filename.ps1 @@ -0,0 +1,28 @@ +# This script serves as a quick Powershell replacement to the search functionality in Windows. +# After you pass in a root folder and a search term, the script will list all files and folders matching that phrase. +param( +[Parameter(Mandatory=$true)] +$path, +[Parameter(Mandatory=$true)] +$term +) +# Recursive search function +Write-Host "Results:" +function Search-Folder($FilePath, $SearchTerm) { + # Get children + $children = Get-ChildItem -Path $FilePath + # For each child, see if it matches the search term, and if it is a folder, search it too. + foreach ($child in $children) { + $name = $child.Name + if ($name -match $SearchTerm) { + Write-Host "$FilePath\$name" + } + $isdir = Test-Path -Path "$FilePath\$name" -PathType Container + if ($isdir) { + Search-Folder -FilePath "$FilePath\$name" -SearchTerm $SearchTerm + } + } +} +# Call the search function +Search-Folder -FilePath $path -SearchTerm $term +exit 0