top of page

PowerShell Multiple System Remote File Search

Search Magnifying Glass

<#  
    ScriptsbyScott.com

    .SYNOPSIS
        Use MS PowerShell to perform recursive search for file types on remote machines 
    .DESCRIPTION
        Gets list of computers to check from txt file
        Executes the MyCommand on remote machine 
        Searches for and returns information on all files with a .txt file extension.
        Searches path under c:\users\ 
        Script was originally created to find Outlook OST, PST files. 
    .NOTES  
        Requires Rights Remote Machines and Folder Path   
        Author: Scott Head
        Min PSVer: Powershell 2.0
        Version: 1.0 (7/7/2019) Script Created     

       Updated: (6/2024) 
    .Special Note 
        When searching user proper rights.
        On local machine I had to disable UAC for full access to C:\Users      
#>

#=================================
# Get List of machines from file 
#=================================   

$Computers= Get-Content C:\Temp\Computers.txt
#==========================================
# Command that executes on remote machine
#==========================================   

$MyCommand={
    # Searched C:\users and all sub folders 
    Get-childitem "c:\users\" -include *.txt -recurse -force -ErrorAction Ignore | select FullName, LastWriteTime 

}
#======================================
# Command Executed on Remote Machines
#======================================        
$JobID=invoke-command -ComputerName $Computers -ScriptBlock $MyCommand -AsJob 

CLS

Write-Output "======Script Executing ========"

#=====================
# Get Data From Job 
#=====================

Receive-Job -id $JobID.ID -Wait| Export-CSV C:\temp\MyFileSearch.csv -Append

#=========================================
# Check File Path Exists and Opens File
#=========================================

If(test-Path C:\temp\MyFileSearch.csv){
    Invoke-Item C:\temp\MyFileSearch.csv
}

CLS

Write-Output "---------Script Completed------------"

I was assigned a task to audit systems that had OST files that were quite large, and I ended up finding them in more than one place but under a specific parent folder. I was able to create a PowerShell script that searches all items and only by file extension and create a report.

bottom of page