Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2011-02-25
12
1,799 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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
 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

856 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