两个AD用户帐户上的Compare-Object [英] Compare-Object on two AD user accounts

查看:220
本文介绍了两个AD用户帐户上的Compare-Object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以比较PowerShell(v2)中的两个ADAccount对象。

Can anyone please give some advice on comparing two ADAccount Objects in PowerShell (v2).

每当我与Compare-Object进行比较时,

Whenever I run a comparison with Compare-Object, it only shows the difference in the Distinguished name, not the differences in the fields of those accounts.

对于每个字段,单独比较$ ADUser.Modified或$ ADUser.DisplayName等等,都不能区分这些帐户的字段。

Short of separately comparing $ADUser.Modified , or $ADUser.DisplayName , etc for every field I want to check, I'm at a loss.

有没有办法比较两个帐户中ADUser对象中的每个字段,显示哪些字段不同?

Is there a way to compare each and every field in the ADUser object across the two accounts, showing which fields are different?

(如果您好奇...这实际上是用于比较同一名称但在不同网域中的两个帐户)

(If you are curious... this is actually for comparing two accounts with the same name, but in different domains)

提前感谢。

推荐答案

这应该给你属性名称,如果相等或不同。

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

这篇关于两个AD用户帐户上的Compare-Object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆