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
245 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article I will provide some simple productivity hacks that will help you use Google to specifically show results from any web site (Experts-Exchange.com in my example), with minimal effort in Chrome and Firefox. I've seen a common theme a…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now