Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Add X500 for a user

Hi,

Add X500 for a user
I want help with adding X500 to all users in a txt file
Can anyone help.

REgards
sharath
Avatar of bsharath
bsharath
Flag of India image

ASKER

I will have the txt file as
Samaccount name;/o=Group/ou=First Administrative Group/cn=Recipients/cn=Samaccountname
Samaccount i mean as Ntlogin
Avatar of evetsleep
evetsleep

are you looking to add the x500 address to a matching sAMAccountName  in Active Directory (in the proxyAddresses attribute)?
Yes
ASKER CERTIFIED SOLUTION
Avatar of markdmac
markdmac
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Mark its perfect
One question with the script
This line
x500Base = "/o=ExampleAB/ou=Organizationalunit1/cn=Recipients/cn="
Will the script run on every user and add like this
x500Base = "/o=ExampleAB/ou=Organizationalunit1/cn=Recipients/cn=Samaccount"
Yes it will.
as you stated some may faile if renamed. how can i find which failed
I have few users Samaccount that i have renamed those may fail i guess
you would need to query against sAMAccountName and compare that to the email address.  How many users are we talking about there?  You could probably grab that info quickly with a custom AD Query in ADUC and just quickly scan the results by eye.  Or dump into Excel and use a formula to compare the two columns.
But
Samaccounts in mine will look as
Sharathy
Email
Sharath.yui@plc.com

I have totally 5000+ users
This is untested but hopefully will give you a list of the accounts that will be in trouble.
On Error Resume Next

Dim qQuery, objConnection, objCommand, objRecordSet, obj
Dim oRootDSE, strDomain

Set oRootDSE = GetObject("LDAP://rootDSE")
strDomain = oRootDSE.get("defaultNamingContext")

' other categories = computer, user, printqueue, group
qQuery = "<LDAP://" & strDomain &">;" & _
		"(objectCategory=person)" & _
       ";sAMAccountName,mailNickname;subtree"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 999 
objCommand.CommandText = qQuery
Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
	If objRecordSet.Fields("sAMAccountName") & "@domain.com" <> objRecordSet.Fields("mailNickname") Then
    	report = report & objRecordSet.Fields("sAMAccountName") & " is different from " & objRecordSet.Fields("mailNickname") & vbCrLf
    End If
    objrecordset.MoveNext
Wend

objConnection.Close

WScript.Echo report

Open in new window

I get all the usrs listed even though they are correct
Sorry I don't have a test environment that I can use for this at the moment.  If they are just one off instances then why not wait for someone to yell and fix them?  
Thanks Mark...
I guess will do it on all and wait for some one who might have a mail bounce thank U
What is the time out there for you.?
Can you have a look at this please... Vbs is also fine on this
https://www.experts-exchange.com/questions/25660679/Powershell-script-to-create-groups-and-add-members.html