mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-25 13:36:39 +01:00
Add search-filename.ps1
This commit is contained in:
parent
330fb1366a
commit
1d0cae88bb
@ -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
|
||||
|
|
@ -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
|
||||
|
28
Scripts/search-filename.ps1
Normal file
28
Scripts/search-filename.ps1
Normal 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
|
Loading…
Reference in New Issue
Block a user