I have been using code from this answer to check for additions/changes to class rosters from MS Teams:
$set = [System.Collections.Generic.HashSet[string]]::new(
[string[]] (Import-CSV -Path stundent.csv).UserPrincipalName,
[System.StringComparer]::InvariantCultureIgnoreCase
)
Import-Csv ad.csv | Where-Object { $set.Add($_.UserPrincipalName) } |
Export-Csv path\to\output.csv -NoTypeInformation
Ideally, I want to be able to check if there have been removals when compared to a new file, swap the import file positions, and check for additions. If my files look like Source1 and Source2 (below), the check for removals would return Export1, and the check for additions would return Export2. Since there will be multiple instances of students across multiple classes, I want to include TeamDesc in the filter query to make sure only the specific instance of that student with that class is returned.
Source1.csv
TeamDesc | UserPrincipalName | Name |
---|---|---|
Team 1 | student1@domain.com | john smith |
Team 1 | student2@domain.com | nancy drew |
Team 2 | student3@domain.com | harvey dent |
Team 3 | student1@domain.com | john smith |
Source2.csv
TeamDesc | UserPrincipalName | Name |
---|---|---|
Team 1 | student2@domain.com | nancy drew |
Team 2 | student3@domain.com | harvey dent |
Team 2 | student4@domain.com | tim tams |
Team 3 | student1@domain.com | john smith |
Export1.csv
TeamDesc | UserPrincipalName | Name |
---|---|---|
Team 1 | student1@domain.com | john smith |
Export2.csv
TeamDesc | UserPrincipalName | Name |
---|---|---|
Team 2 | student4@domain.com | tim tams |