SOLVED

Compare two csv files

Iron Contributor

Hello

 

I am trying to get an idea of devices that have not enrolled in Intune, but are accessing exchange online. I am using two .csv files. The intune file contains all devices that have enrolled in intune and the Exchange file contains all devices that are currently found in Exchange online. I want to compare the two files and export the differences to another .csv file. The two files share a common attribute "deviceid" 

Thank you in advance for any guidance 

 

$Intune = import-csv .\intune.csv | Group-Object -AsHashTable -AsString -Property 'DeviceID'
$Exchange = import-csv .\mobiledevicereport.csv | Group-Object -AsHashTable -AsString -Property 'DeviceID'

2 Replies
best response confirmed by Skipster311-1 (Iron Contributor)
Solution

@Skipster311-1 Give this a try. It'll output two files, one containing the devices that are only in the Intune file, and the other with devices that only exist in the Exchange file.

 

$Intune = Import-CSV .\intune.csv | Group-Object -AsHashTable -AsString -Property 'DeviceID'
$Exchange = Import-CSV .\mobiledevicereport.csv | Group-Object -AsHashTable -AsString -Property 'DeviceID'

$OnlyInIntune = @()
$OnlyInExchange = @()

ForEach ($Device in $Intune.Values) {
    if (!$Exchange[$Device.DeviceID]) {
        $OnlyInIntune += $Device
    }
}

ForEach ($Device in $Exchange.Values) {
    if (!$Intune[$Device.DeviceID]) {
        $OnlyInExchange += $Device
    }
}

$OnlyInIntune | Export-CSV -NoTypeInformation DevicesOnlyInIntune.csv
$OnlyInExchange | Export-CSV -NoTypeInformation DevicesOnlyInExchange.csv
Worked perfectly. Thank you again
1 best response

Accepted Solutions
best response confirmed by Skipster311-1 (Iron Contributor)
Solution

@Skipster311-1 Give this a try. It'll output two files, one containing the devices that are only in the Intune file, and the other with devices that only exist in the Exchange file.

 

$Intune = Import-CSV .\intune.csv | Group-Object -AsHashTable -AsString -Property 'DeviceID'
$Exchange = Import-CSV .\mobiledevicereport.csv | Group-Object -AsHashTable -AsString -Property 'DeviceID'

$OnlyInIntune = @()
$OnlyInExchange = @()

ForEach ($Device in $Intune.Values) {
    if (!$Exchange[$Device.DeviceID]) {
        $OnlyInIntune += $Device
    }
}

ForEach ($Device in $Exchange.Values) {
    if (!$Intune[$Device.DeviceID]) {
        $OnlyInExchange += $Device
    }
}

$OnlyInIntune | Export-CSV -NoTypeInformation DevicesOnlyInIntune.csv
$OnlyInExchange | Export-CSV -NoTypeInformation DevicesOnlyInExchange.csv

View solution in original post