域认证中userPrincipalName 与SamAccountName 差别和使用场景

UserPrincipalName 和 SamAccountName 的 定义和比较

  • UserPrincipalName: 简称 UPN,是客户端进行身份验证的服务的用户主体名称。 格式一般是: 一个用户账号+一个域名, 比如: oscar@mydomain.com (类似电子邮件地址)。 该格式是登录Windows 域的标准用法。
  • SamAccountName: 用于存储账户登录名或用户符号,实际上是命名符号Domain\LogonName。该属性是域用户对象的必需属性。 一般状况,SAMAccountName 应与UPN名称保持一致。即SAMAccountName 等于 UserPrincipalName 的前缀部分。
UserPrincipalNameSamAccountName
登录格式oscar@mydomain.commydomain\oscar
是否必填可选必须
是否唯一唯一唯一
标准基于Internet标准RFC 822的用户Internet样式登录名不能超过20个字符
用于支持以前版本的 Windows (Pre-Windows 2000) 的客户端和服务器

LDAP用户认证方式

LDAP登录的常见的方式有:

  • SAMAccountName  + 密码
  • UserPrincipalName  + 密码

理想状况下,SAMAccountName 应与UPN名称保持一致。即SAMAccountName 等于 UserPrincipalName 的前缀部分。所以其实这两种方式是可以转换的。但是在实际状况中往往会出现不一致的场景。比如以下场景: SAMAccountName 是已知的,但是其并不是按照上面的规则, 也就是无法正确推导出UserPrincipalName  , 该场景的解决思路是:

  1. 使用公用账号查询某个SAMAccountName账号对应的UserPrincipalName 。
  2. 使用UserPrincipalName + 密码进行登录。

AD 属性参考

账号属性
属性名称显示名称说明
userPrincipalNameUserLogon Name用户登录名
sAMAccountnameUser logon name用户登录名,Windows 2000之前的版本
logonHoursLogon Hours登录时间
logonWorkstationLog On To登录到
userAccountControl Account is locked out用户账号控制
pwdLastSetUser must change password at next logon
userAccountControlOther Account Options
accountExpiresAccount Expires账户过期
地址属性
属性名称显示名称说明
streetAddressStreet街道
postOfficeBoxP.O.Box邮政信箱
lCity城市
stState/Province
postalCodeZip/Postal Code邮政编码
c, co, and countryCodeCountry/Region
国家/地区
成员属性
属性名称显示名称说明
memberOfMember of隶属于
primaryGroupIDSet Primary Group
组织属性
属性名称显示名称说明
titleTitle职位
departmentDepartment部门
companyCompany公司
managerManager:Name
directReportsDirect Reports

外型属性

属性名称显示名称说明
profilePathProfile Path配置文件路径
scriptPathLogon Script登录脚本
homeDirectoryHome Folder: Local Path本地路径
homeDriveHome Folder: Connect连接
homeDirectoryHome Folder: To
电话属性
属性名称显示名称说明
telephoneNumberHome
otherTelephoneHome: Other
pagerPager寻呼机
pagerOtherPager: Other
mobileMobile移动电话
otherMobileMobile: Other
FaxfacsimileTelephoneNumber
Fax: OtherotherFacsimileTelephoneNumber
ipPhoneIP phoneIP 电话
otherIpPhoneIP phone: Other
infoNotes注释


  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
抱歉,我是一名AI语言模型,无法为您提供DOS脚本。但是,下面是一个可能有用的PowerShell脚本,可以帮助您迁移AD: ```PowerShell # Set source and target domain information $sourceDomain = "sourcedomain.com" $targetDomain = "targetdomain.com" $sourceDC = "sourcedc.sourcedomain.com" $targetDC = "targetdc.targetdomain.com" # Set credentials for both domains $sourceCreds = Get-Credential -Message "Enter the credentials for the source domain" $targetCreds = Get-Credential -Message "Enter the credentials for the target domain" # Connect to the source domain $sourceSession = New-PSSession -ComputerName $sourceDC -Credential $sourceCreds Import-PSSession $sourceSession -CommandName Get-ADUser, Get-ADGroup, Get-ADObject, Get-ADDomain, Get-ADDomainController, Get-ADOrganizationalUnit, Get-ADGroupMember, Get-ADGroupProperty, Get-ADUserProperty, Get-ADComputerProperty -AllowClobber # Connect to the target domain $targetSession = New-PSSession -ComputerName $targetDC -Credential $targetCreds Import-PSSession $targetSession -CommandName New-ADUser, New-ADGroup, New-ADObject, New-ADOrganizationalUnit, Add-ADGroupMember, Set-ADUser, Set-ADGroup, Set-ADObject, Move-ADObject, Remove-ADObject -AllowClobber # Get all users and groups from the source domain $sourceUsers = Get-ADUser -Filter * -Server $sourceDC $sourceGroups = Get-ADGroup -Filter * -Server $sourceDC # Loop through each user and create a new user in the target domain foreach ($user in $sourceUsers) { $newUser = New-ADUser -Name $user.Name -SamAccountName $user.SamAccountName -UserPrincipalName $user.UserPrincipalName -AccountPassword $user.Password -Enabled $user.Enabled -Server $targetDC Set-ADUser $newUser -DisplayName $user.DisplayName -GivenName $user.GivenName -Surname $user.Surname -EmailAddress $user.EmailAddress Move-ADObject $newUser -TargetPath "OU=Users,DC=targetdomain,DC=com" } # Loop through each group and create a new group in the target domain foreach ($group in $sourceGroups) { $newGroup = New-ADGroup -Name $group.Name -SamAccountName $group.SamAccountName -GroupCategory $group.GroupCategory -GroupScope $group.GroupScope -Server $targetDC Set-ADGroup $newGroup -DisplayName $group.DisplayName -Description $group.Description Move-ADObject $newGroup -TargetPath "OU=Groups,DC=targetdomain,DC=com" $groupMembers = Get-ADGroupMember -Identity $group.Name -Server $sourceDC foreach ($member in $groupMembers) { Add-ADGroupMember -Identity $newGroup.Name -Members $member.SamAccountName -Server $targetDC } } # Disconnect from both domains Remove-PSSession $sourceSession Remove-PSSession $targetSession ``` 请注意,此脚本仅用于示范用途。在实际使用,请仔细检查和测试脚本,以确保它符合您的需求和环境。此外,使用此脚本时,请确保您具有足够的权限来执行所需的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

oscar999

送以玫瑰,手留余香

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值