?
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
Medium Priority
?
265 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

764 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