Scanning for Binaries and Version

I need to list the binaries installed to a folder and below for the software I’m testing.  I can do that with Get-Command on each one, but this allows me to do it recursively and automagically. 

 function Get-LocalBinaries { 
 
param( 
 [string[]]$hostname = @(), 
 [string]$logPath = $null, 
 [switch]$help 
 ); 


 
if ($help) { 
@" 
Get-LocalBinaries [-hostname <string[,string...]>] [-help] 
 Gets all file paths and version numbers for all .exes and .dlls under the specified 
path for the specified host(s), saves as file <hostname>.csv in folder '$env:userprofile' 
(%userprofile% in cmd.exe). 
 -hostname <string[,string...]>] 
List of hostname(s) to scan. 
 -path <string> 
Folder to scan (recursively). 
 -help 
Show this text and return nothing. 
"@ | more; 
return; 
}
  if (!$path) { 
Write-Warning "-path not specified, required. Returning."; 
return; 
} 
 $path = $path -replace ':', '$'; 
foreach ($myHostname in $hostname) { 
if (!$myHostname) { continue; } 
Write-Progress 'Scanning' $myHostname; 
$logPath = "$home\$myHostname.csv"; 
$myPath = \\$myHostname\$path; 
if (!(Test-Path $myPath)) { 
Write-Warning "Unable to access $myPath. Skipping."; 
continue; 
} 
 dir -path $myPath -Recurse -Include *.exe, *.dll | select-object -property @{ 
name = 'hostname'; expression = { $myHostname } 
}, @{ 
name = 'path'; expression = { $_.fullname -replace "\\\\$myHostname\\d\$", "d:" } 
}, @{ 
name = 'version'; expression = { (get-command $_).fileversioninfo.productversion } 
} | export-csv -NoTypeInfo $logPath; 
Write-Verbose -Verbose "$logPath created"; 
} 
} 
  
 Pardon the spacing - trying to figure out a way to nicely post text in this blog is challenging.