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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

705 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

18 Experts available now in Live!

Get 1:1 Help Now