我会说这种说法是不正确的。我无法以编程方式创建超过 20 个字符的用户名。下面是我在 Windows Server 2008 R2 上运行的相关 VB.NET 代码。它适用于创建二十个或更少字符的用户名,但如果用户名超过二十个字符,则会引发异常。自己试试。此致,约瑟夫·达沃利
代码:
Imports System.DirectoryServices 'Gives us access to Directory Services.
Function Blah() As Whatever
Dim strFNMILN As String = "Christopher.B.Robinson" 'NOTE: Twenty-two characters.
Dim strFullName as string = "Christopher B. Robinson"
'Declare a new "DirectoryEntry" object variable and assign to it the entry for
'this computer (the computer on which this code is running).
Dim DirectoryEntryThisComputer As New DirectoryEntry("WinNT://" & Environment.MachineName & ",computer")
'Declare a new "DirectoryEntry" object variable and name it "DirectoryEntryNewUser".
'Create a new user in the local directory and assign that user to our object variable.
Dim DirectoryEntryNewUser As DirectoryEntry = DirectoryEntryThisComputer.Children.Add(strFNMILN, "user")
'Add the fullname of this user.
DirectoryEntryNewUser.Invoke("Put", New Object() {"fullname", strFullName })
'Add a description value.
DirectoryEntryNewUser.Invoke("Put", New Object() {"description", "This is a test user."})
'Set the password for this new user (14 character minimum).
DirectoryEntryNewUser.Invoke("SetPassword", New Object() {"abcdefg1234567"})
'Save this new user to the local directory (this machine's directory).
DirectoryEntryNewUser.CommitChanges()
我在 W2K3 AD 服务器中使用 DSADD,由于“SAMID”的 21(21)个字符长度而失败。
C:\Users\admin-of-change>DSAdd.exe user "CN=SharePoint Service Applications XYZ,OU=Users,OU=District UVW,OU=XYZ,DC=domain-universe,DC=int,DC=net" -samid "adm_xyz_SPServiceApps" -upn [email protected] -fn "SharePoint Service Applications" -ln "XYZ" -display "SharePoint Service Applications XYZ" -pwd "continue2013" -desc "Non Human Account" -office "Head Office" -email [email protected] -webpg "www.UnusualCompany.com" -title "SharePoint Service Applications XYZ" -company "X Y Z" -disabled no
dsadd failed:CN=SharePoint Service Applications XYZ,OU=Users,OU=District UVW,OU=XYZ,DC=domain-universe,DC=int,DC=net:The name provided is not a properly formed account name.
type dsadd /? for help.
┌─────────────────────────────────────┐
│ Executed Tue 07/02/2013 13:59:57.88 │ As [admin-of-change]
└─────────────────────────────────────┘
减少UPN的同时解决了。
C:\Users\admin-of-change>DSAdd.exe user "CN=SharePoint Service Applications XYZ,OU=Users,OU=District UVW,OU=XYZ,DC=domain-universe,DC=int,DC=net" -samid "adm_xyz_SPSvcApps" -upn [email protected] -fn "SharePoint Service Applications" -ln "XYZ" -display "SharePoint Service Applications XYZ" -pwd "continue2013" -desc "Non Human Account" -office "Head Office" -email [email protected] -webpg "www.UnusualCompany.com" -title "SharePoint Service Applications XYZ" -company "X Y Z" -disabled no
dsadd succeeded:CN=SharePoint Service Applications XYZ,OU=Users,OU=Users,OU=District UVW,OU=XYZ,DC=domain-universe,DC=int,DC=net
┌─────────────────────────────────────┐
│ Executed Tue 07/02/2013 14:06:21.08 │ As [admin-of-change]
└─────────────────────────────────────┘
不,它固定在 20。我相信这是出于向后兼容性的原因。您可以在 Active Directory 中变大(SAMAccountName 字段除外),但不能在本地变大。
您必须引用 sam-accountname 属性。登录名必须遵循以下规则:
请注意,GUI 只允许您创建 20 个字符名称,您必须以编程方式创建它们才能超过 20 个。
“请注意,GUI 只允许您创建 20 个字符名称,您必须以编程方式创建它们才能超过 20 个。”
我会说这种说法是不正确的。我无法以编程方式创建超过 20 个字符的用户名。下面是我在 Windows Server 2008 R2 上运行的相关 VB.NET 代码。它适用于创建二十个或更少字符的用户名,但如果用户名超过二十个字符,则会引发异常。自己试试。此致,约瑟夫·达沃利
代码:
我在 W2K3 AD 服务器中使用 DSADD,由于“SAMID”的 21(21)个字符长度而失败。
减少UPN的同时解决了。
欢迎任何改进意见。