I'm stuck with powershell script and need some idea to push me forward, please.
Scenario: This is all about managing information of service accounts in domain. There is a Sharepoint list containing various fileds imported from AD, like AccountName, PasswordLastSet, Enabled. The list also contains manually updated fields like department, admin, comments.
Task: To keep this list up to date, I need periodically update it with fresh export from AD (some columns only, not full record)
1 export the list from AD - done - get-ADuser
2 export the list from Powershell. - done - Get-PnPList
3 compare the lists and for each account from AD, check against Sharepoint list - Struggling here
- if exists, check fields like PasswordLastSet if different update sharepoint list - Done - Set-PnPListItem
- if doesn't exist in sharepoint (new account) create record - Done - Add-PnPListItem
- if exists in Sharepoint but not in AD (deleted account) delete record in SP - Done - Remove-PnPListItem
Problem: I'm stuck with the most important part - compare lists and match records. Tried compare-object, as the most promising but couldn't pick the record right. Any idea how can I get it? with compare-object or any other way...
Any hint appreciated.