Thursday 6 June 2024

Compare-Object on two AD user accounts

 Compare-Object on two AD user accounts

 

This should give you the property name, what each user had as that property and if it was equal or different.

$user1 = get-aduser Test.User1 -Properties *
$user2 = get-aduser Test.User2 -Properties *

$Usercomparison = @()

$user1.GetEnumerator() | ForEach-Object {
    If ($User2.($_.Key) -eq $_.Value)
    {
        $Comparison = 'Equal'
    }
    else
    {
        $Comparison = 'Different'
    }

    $UserObj = New-Object PSObject -Property ([ordered]@{
        Property = $_.Key
        User1 = $_.Value
        User2 = $User2.($_.Key)
        Comparison = $Comparison
    })
    $UserComparison += $UserObj
}

$UserComparison

 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.