Solved

Can PowerShell compare two CSV files? Or should I import the CSV file to multiple worksheets in a single workbook?

Posted on 2015-01-22
3
248 Views
Last Modified: 2015-01-23
Is there a way to import weekly CSV files into an Excel workbook to compare or is there a PowerShell script to compare two CSV files?

Option 1: Within Excel  I want my multiple CSV files to be imported into multiple worksheets within a single workbook only and develop a macro to compare two separate sheets with separate weekly AD group membership information and determine if there is a difference. For example, export from AD, with PowerShell, the group membership and determine weekly if there were additions or deletions from the membership list from the prior week.

Option 2: Develop a PowerShell script to compare two CSV files from Week1 & Week2?

Get-ADGroupMember "Domain Admins" | Export-CSV C:\PowerShellOutput\DomainAdminsGroupMembershipWeek1.csv
Get-ADGroupMember "Schema Admins" | Export-CSV C:\PowerShellOutput\SchemaAdminsGroupMembershipWeek1.csv
Get-ADGroupMember "Enterprise Admins" | Export-CSV C:\PowerShellOutput\EnterpriseAdminsGroupMembershipWeek1.csv
Get-ADGroupMember "Administrators" | Export-CSV C:\PowerShellOutput\AdministratorsGroupMembershipWeek1.csv

Get-ADGroupMember "Domain Admins" | Export-CSV C:\PowerShellOutput\DomainAdminsGroupMembershipWeek2.csv
Get-ADGroupMember "Schema Admins" | Export-CSV C:\PowerShellOutput\SchemaAdminsGroupMembershipWeek2.csv
Get-ADGroupMember "Enterprise Admins" | Export-CSV C:\PowerShellOutput\EnterpriseAdminsGroupMembershipWeek2.csv
Get-ADGroupMember "Administrators" | Export-CSV C:\PowerShellOutput\AdministratorsGroupMembershipWeek2.csv
0
Comment
Question by:CuriousMAUser
  • 2
3 Comments
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40565971
I can give you an option but without Powershell. what about  using Excel Add-Ins and VBA? instead of Powershell?
0
 

Author Comment

by:CuriousMAUser
ID: 40566238
Sure. What are your thoughts ProfessorJimJam?
0
 
LVL 25

Accepted Solution

by:
ProfessorJimJam earned 500 total points
ID: 40566374
oK.

for merging all CSV files into single workbook, use the below code in VBA module.

for example run it in the attached two workbook of CSV files.

then for comparison purposes, use one of these free Add-Ins http://www.ilovefreesoftware.com/30/featured/4-free-add-ins-to-compare-excel-files.html


i have not tested other, but this one only http://sourceforge.net/projects/spreadshcompare/



Sub mergebooks()
    Dim openfiles
    Dim crntfile As Workbook
    Set crntfile = Application.ActiveWorkbook
    Dim x As Integer
    On Error GoTo ErrHandler
    Application.ScreenUpdating = False
    openfiles = Application.GetOpenFilename _
    (FileFilter:="Microsoft Excel Files (*.csv;*.csv),*.csv;*.csv", _
    MultiSelect:=True, Title:="Select Excel file to merge !")

    If TypeName(openfiles) = "Boolean" Then
        MsgBox "You need to select atleast one file"
        GoTo ExitHandler
    End If

    x = 1
    While x <= UBound(openfiles)
        Workbooks.Open Filename:=openfiles(x)
        Sheets().Move After:=crntfile.Sheets(crntfile.Sheets.Count)
        
        x = x + 1
    Wend
ExitHandler:
    Application.ScreenUpdating = True
    Exit Sub

ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler
End Sub

Open in new window

Book1.csv
Book2.csv
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EXCEL: Random Select and Copy 10% of the Row 7 104
Word 2010 mail merge 3 81
Using EXCEL to count the number of Rows 4 71
help with an excel problem 10 29
As freelancing is becoming more and more common in the tech industry, certain obstacles are proving to be a challenge to those who are used to more traditional, structured employment. This article is meant to help identify such obstacles and offer a…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question