?
Solved

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

Posted on 2011-02-25
12
Medium Priority
?
1,810 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
[X]
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
  • 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
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.

 

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
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 to another domain controller. Log onto the new domain controller with a user account t…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

762 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