top of page

PowerShell File Search

<#  
    ScriptsbyScott.com

    .SYNOPSIS
        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     
          
    .Special Note 
        When searching user proper rights.
        On local machine I had to disable UAC for full access to C:\Users 
        https://winaero.com/blog/how-to-turn-off-and-disable-uac-in-windows-10/        
#>


#=================================
# 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------------"

bottom of page