Add search-filename.ps1

This commit is contained in:
Markus Fleschutz 2021-04-10 11:07:40 +02:00
parent 330fb1366a
commit 1d0cae88bb
3 changed files with 30 additions and 0 deletions

View File

@ -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

1 Script Description
122 reboot.ps1 reboots the local computer (requires admin rights)
123 reboot-fritzbox.ps1 reboots the FRITZ!box device
124 remove-empty-dirs.ps1 removes empty subfolders within the given directory tree
125 search-filename.ps1 searches the directory tree for filenames by given pattern
126 search-files.ps1 searches the given pattern in the given files
127 scan-ports.ps1 scans the network for open/closed ports
128 send-email.ps1 sends an email message

View File

@ -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

View File

@ -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