Compare two AD Users in PowerShell imported from LDIF Export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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