Solved

Quest Cmdlet Powershell script to update mail/email attribute on user objects in AD

Posted on 2011-02-25
12
1,784 Views
Last Modified: 2012-05-11
Hello,  I would like to update all users in our AD, local domain, with a email address in the mail attribute of the user object.  mail  = givenname+'@mail.com' .  I am new to using quest cmdlets & powershell.  
this is what i am starting with, but having trouble
Get-QADUser -SearchRoot * | -LdapFilter '(mail='')|   set-qaduser -email "$_.givename@mail.com"

All help is greatly appreciated. thanks
0
Comment
Question by:sp5980
  • 7
  • 4
12 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 34980429
What version of exchange are you using? What you are talking about is applying a recipient policy.
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34980453
Try this, but if you have Exchange it would be easier to create a email policy. And if you have two people with the same first names this could case an problem.

Get-QADUser -SearchRoot "OU=USERSOU,DC=Domain,DC=Local" -LdapFilter "(mail=*)" | set-qaduser -email "$($_.givename)@mail.com"
0
 

Author Comment

by:sp5980
ID: 34980586
Thank you for your comments, i forgot to add, we do not run exchange within our dept.  We are a dept..  in a university.  Email/exchange is handled by central IT group .  And have seperate mgmt & IT domains.  buerocracy at its finest.
0
 

Author Comment

by:sp5980
ID: 34980663
should i use "$_.sAMAccountname" instead of "$_.givenname"?  That should give unique results.
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34980685
Yes, I would recomend useing samaccountname. That can not be duplicated.
0
 

Author Comment

by:sp5980
ID: 34980749
i just ran the script & it didnt add the givenname to teh mail..  the email just shows "@mail.com'
please advise.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 27

Expert Comment

by:KenMcF
ID: 34980787
ok, try this

Get-QADUser -SearchRoot "OU=USERSOU,DC=Domain,DC=Local" -LdapFilter "(mail=*)" | %{set-qaduser $_ -email "$($_.samaccountname)@mail.com"}
0
 

Author Comment

by:sp5980
ID: 34980856
PS C:\Windows\system32> Get-QADUser -SearchRoot "OU=DevClients,DC=SDOS,DC=Local" -LdapFilter "(mail=*)" | set-qaduser -email "$($_.samaccountname)@gmail.com"
result mail = @gmail.com.
     
0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 34980887
You didnt change it. See my last post. Wrap the set-qaduser in a foreach loop

Get-QADUser -SearchRoot "OU=USERSOU,DC=Domain,DC=Local" -LdapFilter "(mail=*)" | %{set-qaduser $_ -email "$($_.samaccountname)@mail.com"}
0
 

Author Comment

by:sp5980
ID: 34980922
Thanks, i got the error below
PS C:\Windows\system32> Get-QADUser -SearchRoot "OU=DevClients,DC=Domain,DC=Local" -LdapFilter "(mail=*)" | %{set-qaduser $_ -email "$($_.samaccountname)@mail.com"}
Get-QADUser : A referral was returned from the server. (Exception from HRESULT: 0x8007202B)
At line:1 char:12
+ Get-QADUser <<<<  -SearchRoot "OU=DevClients,DC=Domain,DC=Local" -LdapFilter "(mail=*)" | %{set-q
aduser $_ -email "$($_.samaccountname)@mail.com"}
    + CategoryInfo          : NotSpecified: (:) [Get-QADUser], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Quest.ActiveRoles.ArsPow
   erShellSnapIn.Powershell.Cmdlets.GetUserCmdlet
0
 

Author Comment

by:sp5980
ID: 34980942
oops, ignore, forgot to change the domain text.
0
 

Author Comment

by:sp5980
ID: 34980952
tried again & it worked!!!   Thanks experts
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now