1

I am comparing 2 DLL files based on name, size, last write time and version using the following script. These files are stored on a remote server. My script is working fine but it is taking too long. Is there a way to optimize my script?

function dll_compare {
    param($path1,$path2) 

    $first = Get-ChildItem -Path $path1 -Filter *.dll
    $second =  Get-ChildItem -Path $path2 -Filter *.dll

    $diff = Compare-Object -ReferenceObject $first -DifferenceObject $second -Property Name, Length, LastWriteTime, VersionInfo -PassThru  | Select Name, Length, LastWriteTime, sideindicator,@{n="VersionInfo";e= { $_.VersionInfo.Productversion }}
    $diff
}
sodawillow
  • 12,497
  • 4
  • 34
  • 44
Shelly Tomar
  • 185
  • 1
  • 10
  • 1. `Compare-DLL` would be a better choice according to naming conventions (see http://stackoverflow.com/questions/24882537/what-is-the-naming-convention-for-powershell-functions-with-regard-to-upper-lowe). 2. How many files can there be in each variable ? – sodawillow Dec 11 '15 at 12:51
  • 3
    You are running the script locally referencing remote paths? Invoke-Command might be a good start in order to run this on the remote machine. – Matt Dec 11 '15 at 13:18
  • Seconded. There can by any number of files ranging from 1 to 100 @sodawillow The paths are remote Matt. – Shelly Tomar Dec 13 '15 at 09:26
  • 1
    Did you try with `Invoke-Command -computerName "ServerName"` and using local paths in the `scriptBlock` as advised by Matt ? That sure should speed up the process. – sodawillow Dec 13 '15 at 15:59
  • I did and it worked! Thank you – Shelly Tomar Dec 14 '15 at 06:30

0 Answers0