Active Directory Management Blog

On our blog you will find of some of our most requested white paper articles on common Active Directory management tasks. SysOp Tools provides active directory management software to assist enterprises with common tasks related to expiring password domain users and domain password policies.

Password Reminder PRO sends email notifications to password expiring users and notifies IT admins of upcoming password related issues.

Password Reset PRO is a secure web based self service solution that allows users to reset an expired password or unlock a locked out account.

For more information visit our website at http://www.sysoptools.com/

Friday, March 26, 2010

Bulk-Adding a Unique SMTP Email Address to NT User Accounts


Download the full article here including screenshots: http://www.sysoptools.com/support/files/Automate%20bulk-adding%20of%20Active%20Directory%20User%20Accounts%20with%20SMTP%20Mailbox%20Address.doc



Problem: Expiring user accounts in Active Directory do not have an email address, and Password Reminder PRO cannot send a password expiration reminder email to the user.


If you need to bulk-add an SMTP email addresses to your non-Exchange-enabled NT user accounts in order to use Password Reminder PRO and other 3rd-party AD management tools, you can now do so very easily with this simple yet powerful script.


The big question: How do I auto-create the first portion of each users email address since it is unique? Each email address has to be the same as the user's NT logon name! How do I easily insert these addresses into the NT account properties for hundreds or thousands of accounts?


Fear not! The below .vbs script looks up the SamAccountName from each user accounts' UPN (logonname@domain.com), and then writes it into the accounts e-Mail field properties of the General tab. Neat-O!


In the script below, you have option to set the portion of '@domain.com' to your environment, as well as the domain and OU path the script should run against. You can do one user, one OU, or the entire domain!
OK- Let's change things!
*Disclaimer- Always test scripts first in a non-production environment!


Prerequisites for editing the user account Mail attribute
Logon to a DC as a domain administrator and run the below script.
Instructions for setting and testing the script
  1. Copy and paste the example script below into notepad.
  2. Change the value in RED for 'yourdomain.com' to your email domain
  3. Change the RED value for LDAP path to point to correct OU and root domain
  4. Save the file with a .vbs extension, for example: AddMailAddress .vbs
  5. Open a CMD prompt, drag/drop the script into the CMD window and hit enter
NOTES:
ALWAYS TEST FIRST! To test script results, create a test user account under a test OU called "TestOU" as in the script below. Run script and you will see the email address inserted under the General properties for that user account. Check that it is the result that you want.
CAUTION! If you run this script against accounts that already have an email address in the e-Mail field of the General tab / user account properties, the existing address will be overwritten!
Sample Script to Batch-Set the Mail Attribute for AD User Objects
(copy area in blue and paste in notepad)


 
' AddMailAddress.vbs
' Sample VBScript to bulk-add email address to AD non mail-enabled user accounts in a domain
' SysOp Tools, Inc – Offered 'as-is' – use with care
' Version 1.0 – August 2007
' --------------------------------------------------------------'
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT AdsPath,samAccountName,userPrincipalName FROM " & _
"'LDAP://OU=TestOU,dc=yourdomain,dc=com' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strUser = objRecordSet.Fields("ADsPath").Value
strNewUPN = objRecordSet.Fields("samAccountName").Value & "@" & "yourdomain.com"
Set objUser = GetObject(strUser)
objUser.Mail = strNewUPN
objUser.SetInfo
objRecordSet.MoveNext
Loop
' -------------------------------------------------------------'
' Important - change LDAP:// path to reflect the proper user, OU, or domain the script should modify
' -------------------------------------------------------------'
' End of Free Sample AddMailAddress VBScript
Need help?

Our dedicated support team is always available to assist you with setup, installation and deployment of our software during your trial period. Your success is our success!

Provided by:
Enterprise Support Team
SysOp Tools, Inc
http://www.sysoptools.com/
Copyright 2007 SysOp Tools, Inc

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.