PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Re: Creating user's CN from Last and First name
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: Creating user's CN from Last and First name

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 15h39   #1
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Creating user's CN from Last and First name

Bartosz Kowalski wrote:

>
> Is it possible to create user with cn=LasName, FirstName ??
> You can do it (by default) using AD Users management on W2K3 Server.
> How can I do it by VBscript?


Commas embedded in the Common Name must be escaped with the backslash escape
character. In brief:
========
strFirstName = InputBox("Enter new user first name")
strLastName = InputBox("Enter new user last name")

' Hard coded parent container.
strParent = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com")

' Create new user object in the parent container.
' Note that the comma is escaped.
Set objUser = objParent.Create("user", "cn=" & strLastName & "\, " &
strFirst Name)

' Assign "pre-Windows 2000 logon name" to be first initial and last name.
' This value must be unique in the domain.
objUser.sAMAccountName = Left(strFirstName, 1) & strLastName

' Make user account enabled.
objUser.AccountDisabled = False

' Save new user object in AD
objUser.SetInfo

' Assign password.
objUser.SetPassword = "xyz312"

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


  Réponse avec citation
Vieux 07/11/2007, 09h10   #2
Bartosz Kowalski
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Creating user's CN from Last and First name

I've made the following script:

strFirstName=InputBox("Enter first name: ")
strLastName=InputBox("Enter last name: ")

lenF=Len(strFirstName)
lenL=Len(strLastName)

strCN=UCase(Left(strLastName,1)) & LCase(Mid(strLastName, 2, lenL-1)) & "\,
" & UCase(Left(strFirstName,1)) & LCase(Mid(strFirstName, 2, lenF-1))

strLogin=Left(LCase(strLastName),2) & LCase(Left(strFirstName,1))

Set objOU = GetObject("LDAP://cn=users,dc=mydomain")

Set objUser = objOU.Create("User", "cn=" & strLastName & "\, " & strFirstName)
objUser.Put "sAMAccountName", strLogin
objUser.Put "sn", strFirstName
objUser.Put "givenName", strLastName
objUser.Put "displayName", strCN
objUser.Put "Name", strCN
objUser.Put "userPrincipalName", strLogin & "@mydomain"
objUser.put "distinguishedName", strCN
objUser.SetInfo

and I received an error message "80072032 An invalid dn syntax has been
specified".

"Richard Mueller [MVP]" wrote:

> Bartosz Kowalski wrote:
>
> >
> > Is it possible to create user with cn=LasName, FirstName ??
> > You can do it (by default) using AD Users management on W2K3 Server.
> > How can I do it by VBscript?

>
> Commas embedded in the Common Name must be escaped with the backslash escape
> character. In brief:
> ========
> strFirstName = InputBox("Enter new user first name")
> strLastName = InputBox("Enter new user last name")
>
> ' Hard coded parent container.
> strParent = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com")
>
> ' Create new user object in the parent container.
> ' Note that the comma is escaped.
> Set objUser = objParent.Create("user", "cn=" & strLastName & "\, " &
> strFirst Name)
>
> ' Assign "pre-Windows 2000 logon name" to be first initial and last name.
> ' This value must be unique in the domain.
> objUser.sAMAccountName = Left(strFirstName, 1) & strLastName
>
> ' Make user account enabled.
> objUser.AccountDisabled = False
>
> ' Save new user object in AD
> objUser.SetInfo
>
> ' Assign password.
> objUser.SetPassword = "xyz312"
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>

  Réponse avec citation
Vieux 07/11/2007, 13h10   #3
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Creating user's CN from Last and First name

You cannot assign a value to the distinguishedName or Name attributes. When
the object is created with:

"cn=" & strLastName & "\, " & strFirstName

the Distinguished Name becomes:

"cn=" & strLastName & "\, " & strFirstName & ",cn=users,dc=mydomain"

It may be that you want to use this instead:

Set objUser = objOU.Create("user", "cn=" & strCN)

You also cannot assign a value to Name. The Name attribute is the "Relative
Distinguished Name" of the object, which in your case will be:

"cn=" & strCN

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Bartosz Kowalski" <BartoszKowalski@discussions.microsoft.com> wrote in
message news:328121B4-77C5-4226-848F-AF3C28C09E1B@microsoft.com...
> I've made the following script:
>
> strFirstName=InputBox("Enter first name: ")
> strLastName=InputBox("Enter last name: ")
>
> lenF=Len(strFirstName)
> lenL=Len(strLastName)
>
> strCN=UCase(Left(strLastName,1)) & LCase(Mid(strLastName, 2, lenL-1)) &
> "\,
> " & UCase(Left(strFirstName,1)) & LCase(Mid(strFirstName, 2, lenF-1))
>
> strLogin=Left(LCase(strLastName),2) & LCase(Left(strFirstName,1))
>
> Set objOU = GetObject("LDAP://cn=users,dc=mydomain")
>
> Set objUser = objOU.Create("User", "cn=" & strLastName & "\, " &
> strFirstName)
> objUser.Put "sAMAccountName", strLogin
> objUser.Put "sn", strFirstName
> objUser.Put "givenName", strLastName
> objUser.Put "displayName", strCN
> objUser.Put "Name", strCN
> objUser.Put "userPrincipalName", strLogin & "@mydomain"
> objUser.put "distinguishedName", strCN
> objUser.SetInfo
>
> and I received an error message "80072032 An invalid dn syntax has been
> specified".
>
> "Richard Mueller [MVP]" wrote:
>
>> Bartosz Kowalski wrote:
>>
>> >
>> > Is it possible to create user with cn=LasName, FirstName ??
>> > You can do it (by default) using AD Users management on W2K3 Server.
>> > How can I do it by VBscript?

>>
>> Commas embedded in the Common Name must be escaped with the backslash
>> escape
>> character. In brief:
>> ========
>> strFirstName = InputBox("Enter new user first name")
>> strLastName = InputBox("Enter new user last name")
>>
>> ' Hard coded parent container.
>> strParent = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com")
>>
>> ' Create new user object in the parent container.
>> ' Note that the comma is escaped.
>> Set objUser = objParent.Create("user", "cn=" & strLastName & "\, " &
>> strFirst Name)
>>
>> ' Assign "pre-Windows 2000 logon name" to be first initial and last name.
>> ' This value must be unique in the domain.
>> objUser.sAMAccountName = Left(strFirstName, 1) & strLastName
>>
>> ' Make user account enabled.
>> objUser.AccountDisabled = False
>>
>> ' Save new user object in AD
>> objUser.SetInfo
>>
>> ' Assign password.
>> objUser.SetPassword = "xyz312"
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16717 seconds with 11 queries