Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Created March 7, 2023 00:42
Show Gist options
  • Save darrenjrobinson/9b1c6df89b34284f59b644aaef834622 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/9b1c6df89b34284f59b644aaef834622 to your computer and use it in GitHub Desktop.
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