compareobject

PowerShell: Function doesn't have proper return value

旧巷老猫 提交于 2019-12-12 10:46:09
问题 I wrote a powershell script to compare the content of two folders: $Dir1 ="d:\TEMP\Dir1" $Dir2 ="d:\TEMP\Dir2" function Test-Diff($Dir1, $Dir2) { $fileList1 = Get-ChildItem $Dir1 -Recurse | Where-Object {!$_.PsIsContainer} | Get-Item | Sort-Object -Property Name $fileList2 = Get-ChildItem $Dir2 -Recurse | Where-Object {!$_.PsIsContainer} | Get-Item | Sort-Object -Property Name if($fileList1.Count -ne $fileList2.Count) { Write-Host "Following files are different:" Compare-Object

Adding Results from Compare-Object to Array

試著忘記壹切 提交于 2019-12-11 18:39:02
问题 I have two files being compared, one a CSV and one a txt file. The CSV file has the information for around 5,000 servers and the txt file has only server names for around 3,000. The columns within the CSV are Name, OS, and Type. This is what I did to compare the objects: $compareObject = Compare-Object -ReferenceObject $txtFile -DifferenceObject $csvFile.Name -IncludeEqual After this, I was then given three options. Ones that are on both lists == , ones that are only on the txt file => , and

delete everything after keyword

青春壹個敷衍的年華 提交于 2019-12-11 18:19:13
问题 I try to merge to files with Compare-Object and I got a file like this: Number=5 Example=4 Track=1000 Date=07/08/2018 19:51:16 MatCaissierePDAAssoc= NomImpPDAAssoc= TpeForceLectPan=0 Number=1 Example=1 Track=0 Date=01/01/1999 You can see it repeats with Number=1. Except with a different value. I would like to delete everything (everything means not only "= 1") after my keyword "Number" and my keyword itself. This is what I did so far: $files = Get-ChildItem "D:\all" foreach ($file in $files)

Comparing files based on version number and some other criteria and Formatting the output

心已入冬 提交于 2019-12-11 10:46:44
问题 I am comparing 2 files based on size, last write time and version number using Compare-object in Powershell. I am getting the results. The only problem is how to get the value of the version number from the result. 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 |

Compare two text files and write the differences to text file

醉酒当歌 提交于 2019-12-07 23:54:35
问题 I want to compare 2 text files and output the difference in another text file. $Location = "c:\temp\z.txt" compare-object (get-content c:\temp\hostname_old.txt) (get-content c:\temp\hostname_new.txt) | format-list | Out-File $Location hostname_old.txt server02 server05 server04 server06 server01 hostname_new.txt server04 server01 server02 Results InputObject : server05 SideIndicator : <= InputObject : server06 SideIndicator : <= This is what I want : (get rid of both InputObject and

Compare two text files and write the differences to text file

做~自己de王妃 提交于 2019-12-06 08:21:28
I want to compare 2 text files and output the difference in another text file. $Location = "c:\temp\z.txt" compare-object (get-content c:\temp\hostname_old.txt) (get-content c:\temp\hostname_new.txt) | format-list | Out-File $Location hostname_old.txt server02 server05 server04 server06 server01 hostname_new.txt server04 server01 server02 Results InputObject : server05 SideIndicator : <= InputObject : server06 SideIndicator : <= This is what I want : (get rid of both InputObject and SideIndicator) server05 server06 Note: A related problem where one input file has duplicate entries is the

Compare two CSV and export only a list of names that don't exist in both

江枫思渺然 提交于 2019-12-06 06:11:09
I have 2 CSV files with user names. I want to export just the names of users who don't exist in both files. The code I have now: $file1 = import-csv -Path "C:\ps\output\adusers.csv" $file2 = import-csv -Path "C:\ps\output\users.csv" Compare-Object $file1 $file2 -property name | Export-Csv -NoTypeInformation -Path "C:\ps\result\result.csv" wOxxOm Use Select-Object name to extract only the name field from Compare-Object's output: Compare-Object $file1 $file2 -Property name | select name | sort -unique -Property name | Export-Csv -NoTypeInformation -Path "C:\ps\result\result.csv" Notes: sort