- Home
-
Store
- Browse All
- SHARED HOSTING
- VPS SERVER
- DEDICATED SERVER
- DATABSE HOSTING
- RESELLER HOSTING
- EMAIL HOSTING
- FTP HOSTING
- Hosting Addons
- SSL Certificates
- Weebly Website Builder
- SiteLock
- Email Spam Filtering
- CodeGuard
- SSL Certificates
- Website Builder
- Website Security
- E-mail Services
- Website Backup
- SEO Tools
- Site Builder
- VPN
- Professional Email
- XOVI NOW
- Register a New Domain
- Transfer Domains to Us
- Announcements
- Knowledgebase
- Network Status
- Contact Us
-
More
Categories
Categories
Tag Cloud
PowerShell – Updating Users Email Addresses In Active Directory Print
- PowerShell – Updating Users Email Addresses In Active Directory, Updating Users Email Addresses In Active Directory
- 0
Problem
Note: I’m referring to the Email address value that is listed on the user object in Active Directory, this will not effect any Exchange Settings!
A colleague asked me today if I had any PowerShell to update ALL the users in a clients AD, to match their UPN to their Email addresses. A quick internet search turned up loads of handy scripts to update the UPN to mach the email address, but not the way round he wanted.
Solution
In most (not all) cases your UPN is the same as your sAMaccountname and your domain name, so you can simply run the following;
Import-Module ActiveDirectory Get-ADUser -Filter * -SearchBase 'DC=test,DC=net' | ` ForEach-Object { Set-ADUser -EmailAddress ($_.samaccountname + '@test.net') -Identity $_ }
Note: Save the above as a file with a .ps1 extension, or execute both commands separately.
Now you may, (like on my test network above,) have your user logon name set to something other than firstname.lastname if so and you would prefer to set the Email value to firstname.lastname@domain.com then use the following instead.
Import-Module ActiveDirectory Get-ADUser -Filter * -SearchBase 'DC=test,DC=net' | ` ForEach-Object { Set-ADUser -EmailAddress ($_.givenName + '.' + $_.surname + '@test.net') -Identity $_ }
Note: Save the above as a file with a ps1 extension, or execute both commands separately.