Compare CSV's and Outputting them in a Proper Table

I have written a script to gather information from multiple servers. These include CSVs for Services, Applications, Users etc.

Although I can run a Compare-Object on these CSVs, the output isn’t great.

So I would like to compare the Services CSV on 2 servers and put into one table

Name StartMode(server1) StartMode(Server2) State(Server1) State(Server2) Status(Server1) Status(Server2)

AppInfo Manual Auto Stopped Running OK OK

Service2 Manual Auto Stopped Running OK OK



The troubles I am running into are, my headers are different per CSV and I can’t get all the columns on one line. I end up with AppInfo on two lines with the Server1 on one and Server2 on the second.


Any ideas would be great please. It needs to be dynamic to accept all headers from different CSVs.



I am trying to understand the mismatch between the CSV files. Are you saying that the “services.csv” files for two different servers contain different headers? Are you using the same script to create the files? If possible can you provide the two different headers sets? In that case, I would think that any Compare-Object operation will result if differences in every line of the CSV. Maybe you could illustrate your input and the desired output.



Even I am trying to understand the actual requirement. However, I am pasting the script which I think, could be your requirement. Do let us know your desired output.


$computers = "LocalHost", "localhost"

foreach ($computer in $computers){
$serviceName = "WpnUserService_569ce"
Get-CimInstance -ClassName Win32_service -ComputerName $computer | Where {$_.Name -eq $ServiceName}

ProcessId Name                 StartMode State   Status ExitCode PSComputerName
--------- ----                 --------- -----   ------ -------- --------------
0         WpnUserService_569ce Manual    Stopped OK     1077     LocalHost     
0         WpnUserService_569ce Manual    Stopped OK     1077     localhost

Thank you for your replies. I have a group of machines that should be identical. The 1st script I have written compiles several CSVs. For example, a list of users, a list of running services, a list of installed software.

The compare script should then go through each CSV and compare them. So Comp1 Application CSV with Comp2 Application CSV, Comp1 User CSV with Comp2 User CSV. This is why the headers would be different, as the User CSV will have different headers to the Service CSV to the Application CSV.

So for Services the output would be:

Name                     StartMode Comp1         State Comp1             Status Comp1            StartMode Comp2         State Comp2             Status Comp2           
----                     ---------------         -----------             ------------            ---------------         -----------             ------------           
WpnUserService_569ce     Manual                  Stopped                 OK                      Auto                    Stopped                 OK                     
AppInfo                  Auto                    Running                 OK                      Auto                    Stopped                 OK

But for the Application it would be:

Name                     Version Comp1           Vendor Comp1            Package Comp1           Version Comp2           Vendor Comp2            Package Comp2          
----                     -------------           ------------            -------------           -------------           ------------            -------------          
Office 2010              2010.123.321            Microsoft               Office.msi              2010.321.132            Microsoft               Office.msi             
Chrome                   123456                  Google                  Chrome.msi              535626                  Google                  Chrome.msi

Different Headers.

Well, for one thing, Compare-Object doesn’t normally give output that looks anything like that, it normally only shows things that are different. Could you please show us the script itself? It’s hard to give recommendations while blind.