Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Created March 7, 2023 00:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Compare two AD Users in PowerShell imported from LDIF Export
$BeforeExport = Get-LDIFRecords -InputFile .\AU_export_before.ldf
$AfterExport = Get-LDIFRecords -InputFile .\AU_export_after.ldf
# Get Users from LDIF to PSObject
$userOne = (Get-LDIFUser -employeeID 100101 -LDIFObject $BeforeExport)
$userTwo = (Get-LDIFUser -employeeID 100101 -LDIFObject $AfterExport)
# Get the attributes from each user object
$userOneAttrs = ($userOne | Get-Member | Where-Object { $_.membertype -eq "NoteProperty" } | Select-Object -Property name -ExcludeProperty dn).Name
$userTwoAttrs = ($userTwo | Get-Member | Where-Object { $_.membertype -eq "NoteProperty" } | Select-Object -Property name -ExcludeProperty dn).Name
# Reformat PSObjects
$userOneObj = @{}
foreach ($attribute in $userOneAttrs) {
$userOneObj.add($attribute, $userOne.$attribute)
}
$userTwoObj = @{}
foreach ($attribute in $userTwoAttrs) {
$userTwoObj.add($attribute, $userTwo.$attribute)
}
# Compare
$properties = ($userOneObj | Get-Member -MemberType Property | Select-Object -ExpandProperty Name)
$out = @()
foreach ($property in $properties) {
$out += Compare-Object $userOneObj $userTwoObj -Property "$property" -IncludeEqual # | Format-Table -AutoSize
}
# Obj 1 is Diff
$out[6] | Format-List
# Obj 2 is Diff
$out[5] | Format-List
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment