Powershell | Search Directory for files matching CSV

I currently use Adaxes to manage all our AD/Exchange accounts and have a report built to find accounts missing staff photos. I’ve wanted to streamline this process as currently we have our front off staff take staff photos when they’re onboarded then dump the photos into a network share. In doing some account clean up I needed an easy way to search a network share for photos matching staff names in a CSV.

After some searching this is what I came up with and has been working well!

 $CSVFile = "C:\Temp\users without photos.csv"
 $SearchDir = "\\adss\_Exchange-Photos\"

 ForEach ($Name in (Import-Csv -Path $CSVFile )){
     # Search within path for files matching CSV filename pattern
     Get-Childitem -Path $SearchDir -File -Filter ($Name.Name + "*") | Foreach {
         #On each source jpg found in the folder, copy it into the folder which matches value from CSV
         Copy-Item $_.fullname -Destination ("C:\temp\" + $Name.filename)
         Write-Output "Found match and copied: $_"
My temp dir after running the script and finding a match
Powershell output
CSV Format

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top