File Search Script by Name with Endpoint Central

Searching for Files by Name with Endpoint Central

Aim

This script allows you to use a specific file name to identify which computers have that file.

You can easily search for the targeted file by running this script via Endpoint Central.

Script Details

The following PowerShell script searches all drives for the specified file and lists the locations where it is found:

Powershell
# Define the file name to search for
$filename = "test.txt" # You can update the file name here.

# Get all drivers on computer
$drives = Get-PSDrive | Where-Object { $_.Provider -match 'FileSystem' }

# Search for file in all drives
$searchResults = Get-ChildItem -Path $drives.Root -Filter $filename -Recurse -ErrorAction SilentlyContinue

# Check if the file exists
if ($searchResults) {
# Display the full path of the found file
Write-Host "File '$filename' found in:"
$searchResults | ForEach-Object { Write-Host $_.FullName }
} else {
# If file not found
Write-Host "File '$filename' not found."
}


Instructions for Use

Define File Name: Type the name of the file to be searched in the $filename variable.

For example, test.txt.

Run the Script: Add this script to the script repository via Endpoint Central and apply it to the target computers.



Examine the Results: Once the script is complete, the full paths where the file is located will be displayed in the console.

If the file is not found, you will receive a “File not found” message.