I have seen various posts that cover similar topics to this. But none that match my exact requirements.
My aim is:
- Use a CSV containing col 1 (
ADGroupName
), col 2 (extensionAttirbute1
) - Delete users from AD groups based on CSV
- Add users to AD groups based on CSV
I'm sure this can be done simply however, to get it to work with the extensionAttribute1
value, is proving difficult.
Below is some of the code:
So, I have 2 functions.
- First creates CSVs to work from. (Working).
- Second function adds/removes AD groups based on CSV contents. (Working).
Below is where I left the final function after wiping out various bits of code after it didn't work.
Function SyncGroups {
$Groups = Import-Csv "C:\Temp\Scripts\GroupMembership.csv"
foreach ($user in $Groups) {
Add-ADGroupMember -Identity $user.Group -Members $user.extensionAttribute1
Get-ADUser -Filter {extensionAttribute1 -eq $user.extensionAttribute1}
}
}