当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 转换 Active Directory 中的 UserAccountControl 属性值

作者:精品下载站 日期:2024-12-14 23:18:40 浏览:15 分类:玩电脑

转换 Active Directory 中的 UserAccountControl 属性值


UserAccountControl 是 Active Directory 中用户和计算机对象最重要的属性之一。该属性决定了 AD 域中帐户的状态:帐户是活动的还是锁定的、是否启用下次登录时更改密码的选项、用户是否可以更改密码等。但是,并非所有管理员都完全了解 UserAccountControl 属性的工作原理以及它在 AD 中的用途

Active Directory 中的 UserAccountControl 属性/标志

打开 Active Directory 用户和计算机中任何 AD 帐户的属性(ADUC、

dsa.msc

) 控制台并转到帐户选项卡。请注意帐户选项部分中的用户属性组。在这里您可以看到以下选项:

  • 用户下次登录时必须更改密码;

  • 用户无法更改密码;

  • 密码永不过期;

    默认情况下,AD 中的域密码策略要求用户定期更改密码。

  • 使用可逆加密存储密码(不安全);

  • 帐户已被禁用;

  • 交互式登录需要智能卡;

  • 账户敏感,无法委托;

  • 为此帐户使用 Kerberos DES 加密类型;

  • 该账户支持Kerberos AES 128/256位加密;

  • 不需要 Kerberos 预身份验证。

[玩转系统] 转换 Active Directory 中的 UserAccountControl 属性值

这些用户帐户属性中的每一个本质上都是一个位值(标志),可以是 1 (

True

) 或 0 (

False

)。但是,这些值不会存储为单独的 AD 属性,而是使用 UserAccountControl 属性。

上面指定的所有选项的总值存储在 UserAccountControl 属性的值中。使用单个 Active Directory 属性,而不是将所有这些选项存储在不同的用户属性中。 UserAccountControl 是一个位掩码,其中的每一位都是一个单独的标志,并且具有值 (True) 或 (False)。根据启用的帐户选项,用户将具有不同的 UserAccountControl 属性值。您可以在相应的属性编辑器选项卡中或使用 PowerShell 中的 Get-ADUser cmdlet 查看属性的当前值:

get-aduser jkelly -properties *|select name,UserAccountControl | ft

[玩转系统] 转换 Active Directory 中的 UserAccountControl 属性值

[玩转系统] 转换 Active Directory 中的 UserAccountControl 属性值

在此示例中,属性值为0x10202(十进制值为66050)。这些数字意味着什么?

下面给出了 AD 帐户的可用标志表。每个标志对应于某个UserAccountControl位,并且UserAccountControl值等于所有标志的总和。

UserAccountControl FlagHEX ValueDecimal ValueSCRIPT (Running the logon script)0x00011ACCOUNTDISABLE (The account is disabled)0x00022HOMEDIR_REQUIRED (The home folder is required)0x00088LOCKOUT (The account is locked)0x001016PASSWD_NOTREQD (No password is required)0x002032PASSWD_CANT_CHANGE (Prevent user from changing password)0x004064ENCRYPTED_TEXT_PWD_ALLOWED (Store password using reversible encryption)0x0080128TEMP_DUPLICATE_ACCOUNT (An account of a user, whose primary account is in another domain)0x0100256NORMAL_ACCOUNT (A default account, a typical active account)0x0200512INTERDOMAIN_TRUST_ACCOUNT0x08002048WORKSTATION_TRUST_ACCOUNT0x10004096SERVER_TRUST_ACCOUNT0x20008192DONT_EXPIRE_PASSWORD (user accounts with passwords that don’t expire)0x1000065536MNS_LOGON_ACCOUNT0x20000131072SMARTCARD_REQUIRED (To log on to the network, the user needs a smart card)0x40000262144TRUSTED_FOR_DELEGATION0x80000524288NOT_DELEGATED0x1000001048576USE_DES_KEY_ONLY0x2000002097152DONT_REQ_PREAUTH (Kerberos pre-authentication is not required)0x4000004194304PASSWORD_EXPIRED (The user password has expired)0x8000008388608TRUSTED_TO_AUTH_FOR_DELEGATION0x100000016777216PARTIAL_SECRETS_ACCOUNT0x0400000067108864

例如,有一个常规帐户禁用了更改密码的要求。 userAccountControl 值计算如下:

NORMAL_ACCOUNT (512) + DONT_EXPIRE_PASSWORD (65536) = 66048

因此,我的示例中 userAccountControl 的值 (66050) 的获取方式如下:

NORMAL_ACCOUNT (512) + DONT_EXPIRE_PASSWORD (65536) + ACCOUNTDISABLE (2) = 66050

禁用的用户帐户的 userAccountControl 值是 514:

(NORMAL_ACCOUNT (512)+ ACCOUNTDISABLE (2) = 514

典型域对象的默认 UserAccountControl 值:

  • 普通AD用户:0x200(512);

  • 域控制器:0x82000(532480);

  • 工作站/服务器:0x1000 (4096)。

您可以使用 LDAP 过滤器从具有特定 useraccountcontrol 值的 AD 对象中选择对象。例如,要显示所有活动(正常)帐户:

Get-ADUser -Properties * -ldapFilter "(useraccountcontrol=512)"

显示所有禁用的用户帐户的列表:

Get-ADUser -Properties * -ldapFilter "(useraccountcontrol=514)"

具有不过期密码选项的帐户列表:

Get-ADUser -Properties * -ldapFilter "(useraccountcontrol=66048)"

您可以使用以下命令对表中所需的位求和并选择 AD 对象:

$UserAccountControl_hex= 0x10000 + 0x0080 + 0x200000
Get-ADUser -Filter {UserAccountControl -band$UserAccountControl_hex}

使用 PowerShell 脚本解码 UserAccountControl 值

为了使它更方便,我希望有一个工具可以自动将 UserAccountControl 位掩码的值转换为人类透明的形式。让我们尝试编写一个简单的 PowerShell 函数,该函数采用 UserAccountControl 属性的十进制值并返回已启用的帐户选项的列表。由于 UserAccountControl 是位掩码,因此您可以为每个位分配文本描述。

我编写了这个 PowerShell 函数 DecodeUserAccountControl 将 UserAccountControl 值转换为可读形式:

Function DecodeUserAccountControl ([int]$UAC)
{
$UACPropertyFlags = @(
"SCRIPT",
"ACCOUNTDISABLE",
"RESERVED",
"HOMEDIR_REQUIRED",
"LOCKOUT",
"PASSWD_NOTREQD",
"PASSWD_CANT_CHANGE",
"ENCRYPTED_TEXT_PWD_ALLOWED",
"TEMP_DUPLICATE_ACCOUNT",
"NORMAL_ACCOUNT",
"RESERVED",
"INTERDOMAIN_TRUST_ACCOUNT",
"WORKSTATION_TRUST_ACCOUNT",
"SERVER_TRUST_ACCOUNT",
"RESERVED",
"RESERVED",
"DONT_EXPIRE_PASSWORD",
"MNS_LOGON_ACCOUNT",
"SMARTCARD_REQUIRED",
"TRUSTED_FOR_DELEGATION",
"NOT_DELEGATED",
"USE_DES_KEY_ONLY",
"DONT_REQ_PREAUTH",
"PASSWORD_EXPIRED",
"TRUSTED_TO_AUTH_FOR_DELEGATION",
"RESERVED",
"PARTIAL_SECRETS_ACCOUNT"
"RESERVED"
"RESERVED"
"RESERVED"
"RESERVED"
"RESERVED"
)
return (0..($UACPropertyFlags.Length) | ?{$UAC -bAnd [math]::Pow(2,$_)} | %{$UACPropertyFlags[$_]}) -join ” | ”
}

让我们检查一下 UserAccountControl 的值 66050 意味着什么:

DecodeUserAccountControl 66050

正如您所看到的,脚本返回该用户启用了以下标志:

帐户禁用 |普通帐户 | DONT_EXPIRE_PASSWORD

[玩转系统] 转换 Active Directory 中的 UserAccountControl 属性值

使用 Get-ADUser 或 Get-ADComputer cmdlet 以方便的形式获取有关 AD 帐户的信息时,可以使用相同的脚本动态解码 UserAccountControl 值,例如:

get-aduser ms-pam -properties *|select @{n='UsrAcCtrl';e={DecodeUserAccountControl($_.userAccountControl)}}

帐户禁用 |普通帐户 | DONT_EXPIRE_PASSWORD

get-adcomputer rome-dc01 -properties *|select @{n='UsrAcCtrl';e={DecodeUserAccountControl($_.userAccountControl)}}

SERVER_TRUST_ACCOUNT | TRUSTED_FOR_DELEGATION

[玩转系统] 转换 Active Directory 中的 UserAccountControl 属性值

如何使用 PowerShell 在 AD 中设置 UserAccoutControl 属性?

您可以使用 Set-ADUser 和 Set-ADComputer PowerShell cmdlet 更改 Active Directory 中 UserAccountControl 属性的各个选项。这两个 cmdlet 都有单独的选项,例如:

  • 账户未授权

  • 允许可逆密码加密

  • 无法更改密码

  • 登录时更改密码

  • Kerberos加密类型

  • 密码永不过期

  • 不需要密码

  • 允许委托人委托帐户

AD中的计算机帐户密码提供了计算机和域之间的信任关系。

因此,要更改一些用户选项,您需要使用以下命令:

Set-ADUser jkelly -CannotChangePassword:$true -PasswordNeverExpires:$true

或者您可以使用通用的 Set-UserAccountControl cmdlet:

Set-ADAccountControl -Identity jkelly -CannotChangePassword $True -PasswordNeverExpires $True

[玩转系统] 转换 Active Directory 中的 UserAccountControl 属性值

您还可以通过 UserAccountControl 属性设置确切的值来直接启用这两个用户帐户选项:

Set-ADUser jkelly -Replace @{UserAccountControl= 66048}

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯