Solved

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

Posted on 2011-02-25
12
1,781 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This article will help you understand what HashTables are and how to use them in PowerShell.
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 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…

757 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

20 Experts available now in Live!

Get 1:1 Help Now