2

I am comparing dll files based on size, last write time and version number using Compare-object in Powershell. These files are stored on remote servers. I am getting the result. The only problem is how to get the value of the version number from the result. In my previous question, I was following a different approach which was not optimized, you can view it here : Comparing files based on version number and some other criteria and Formatting the output My updated script is:

$s1=New-PSSession -ComputerName $c1
$first=Invoke-Command -Session $s1 -ScriptBlock{param($path1) Get-ChildItem -Path $path1 -Filter *.dll} -ArgumentList $path1

$s2=New-PSSession -ComputerName $c2
$second=Invoke-Command -Session $s2 -ScriptBlock{param($path2) Get-ChildItem -Path $path2 -Filter *.dll} -ArgumentList $path2

$diff = Compare-Object -ReferenceObject $first -DifferenceObject $second -Property Name, Length, LastWriteTime, VersionInfo -PassThru  | Select Name, Length, LastWriteTime, sideindicator,@{n="VersionInfo";e= { $_.VersionInfo.Productversion }}
$diff

Here c1 and c2 are computer names and path1 and path2 are the paths of the folders in c1 and c2 respectively. The output does not contain version number. It is of following format:

Name          : PhotoViewer.dll
Length        : 20480
LastWriteTime : 8/9/2015 4:46:08 PM
SideIndicator : <=
VersionInfo   : 
Community
  • 1
  • 1
Shelly Tomar
  • 185
  • 1
  • 10

1 Answers1

1

there is probably a limit to the depth, to which object properties are de-serialized. anyway here is one approach that could work.

check this link for more info link

$first=Invoke-Command -Session $s1 -ScriptBlock{param($path1) Get-ChildItem -Path $path1 -Filter *.dll | Export-Clixml -Path '\\networkshare\first.xml' } -ArgumentList $path1

$second=Invoke-Command -Session $s2 -ScriptBlock{param($path2) Get-ChildItem -Path $path2 -Filter *.dll |  Export-Clixml -Path '\\networkshare\second.xml'} -ArgumentList $path2

$first_xml = Import-Clixml -Path '\\networkshare\first.xml'
$second_xml = Import-Clixml -Path '\\networkshare\second.xml'

Compare-Object -ReferenceObject $first_xml -DifferenceObject $second_xml -Property Name, Length, LastWriteTime, VersionInfo -PassThru  | 
 Select-Object Name, Length, LastWriteTime, sideindicator,@{n='VersionInfo';e= { $_.VersionInfo.productversion }}
Kiran Reddy
  • 2,836
  • 2
  • 16
  • 20
  • I am getting an error in this approach: "Import-Clixml : Root element is missing." – Shelly Tomar Dec 15 '15 at 12:46
  • are the 2 xml files generated on the network share?...also does it work if you just do it on your localsystem instead of on the network.( do the `export-clixml` on say c:\temp and then run `import-clixml` to see if it works. – Kiran Reddy Dec 15 '15 at 23:52
  • It worked now when i used invoke-command for import-clixml too. Thanks :) – Shelly Tomar Dec 16 '15 at 04:11