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
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

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 26

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

724 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