I created this script when we needed to search all user network shares, as well as business department shares for PST files. We were in the process of migrating to a central email archiving solution and needed to get an idea on the possible storage requirements that would be required for importing all user PST files.
This script is simple, but very universal, as you’re able to enter any directory and file name/extension.
The above example searched my Downloads folder for “license.” The resulting report provided all files with “license” in the name:
Copy the script or Download
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
############################################################################################# # Script can find files matching the entered name and directory. # A report is generated that contains file name, directory, size, last modified and accessed dates. #### #### This script was previous used to search hundreds of user/department shares for PST files. #### For example: Directory (\\fileserver\user_Shares\), File: ".PST" #### ############################################################################################# # Prompt user for settings "`n" write-Host "---------------------------------------------" -ForegroundColor Yellow $filePath = Read-Host "Please Enter File Path to Search" write-Host "---------------------------------------------" -ForegroundColor Green $fileName = Read-Host "Please Enter File Name (or extension) to search for" write-Host "---------------------------------------------" -ForegroundColor Yellow $Reportfile = Read-Host 'Please Enter File Name for report ("C:\Temp\Report.csv")' write-Host "---------------------------------------------" -ForegroundColor Green "`n" # Command to get items. $items = Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and ( $_.Name -like "*$fileName*") } | Select-Object Name,FullName,Directory,length,lastwritetime,lastaccesstime foreach($i in $items){ # Get item and format file size to MB $currentSize1 = get-childitem $i.Fullname | select @{nAME="MBytes";EXPRESSION={ "{0:N0}" -f ($_.Length / 1MB)}} $currentSize2 = $currentSize1.MBytes $shortModified = $i.lastwritetime.ToString("yyyy/MM/dd") $shortAccessed = $i.lastaccesstime.ToString("yyyy/MM/dd") $list = New-Object psobject $list | add-member NoteProperty Name $i.Name $list | Add-Member NoteProperty Directory $i.directory $list | Add-Member NoteProperty MBytes $currentSize2 $list | Add-Member NoteProperty LastModified $shortModified $list | Add-Member NoteProperty LastAccessed $shortAccessed write-host $list $list | export-csv -Path $ReportFile -append } "`n" write-Host "------------END of Result--------------------" -ForegroundColor Magenta |