Setting the SMTP address when an email policy won’t do the trick

I’m migrating a bunch of users from one domain to another. The client promised the end users that the first part of their email shall remain the same, only the domain changes. So, for example, if Bob Jones email address is Bob-the-dude@xyz.com , the default email policy would create bob.jones@abc.com, but the client promised the end users that it would be bob-the-dude@abc.com.

Input file that looks like this:

emailaddress,SamAccountName
bob-the-dude@abc.com,BJONES
happydoug@abc.com,DSMITH
theprez@abc.com,TSMITH

The script unchecks the “Automatically update e-mail addresses based on e-mail address policy”, and then it assigns a new primary smtp address.

$CSV = Import-CSV C:\temp\first50-smtp.csv
foreach ($entry in $Csv) {
Set-mailbox -identity $entry.samaccountname -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $entry.emailaddress
}
Advertisements

Check for existing user in active directory

This powershell script below allows me to take
an input file that looks like this (input-users.csv)

SamAccountName
ksk34
xyz444
jsmith
bjones

and make an output file that will look like this (out.csv)

ksk34,yes
xyz444,no
jsmith,no
bjones,yes

The client I was working at did NOT have any windows 2008 dcs, so i could not use the command get-aduser, instead I installed the quest tools and I am using get-qaduser

Basically, this script give me a yes or no to the question “does the user (samaccount) exist?” Special thanks to Raymond for helping me with the output (I’m still new at powershell)

$users = Import-Csv c:\scripts\input-users.csv
foreach ($user in $users)
{
 if (get-qaduser -SamAccountName $user.SamAccountName)
 {
 #Found...
 "$($user.SamAccountName),yes" | out-file out.csv -append
 }
 else
 {
 #NOT Found...
 "$($user.SamAccountName),no"| out-file out.csv -append
 }
}

========AND ANOTHER VERSION OF THIS LOOKS LIKE THIS====

$users = Import-Csv c:\temp\ALLSMTP1.csv
 foreach ($user in $users)
 {
 if (get-qaduser -email $user.SMTPaddress)
 {
 #Found...
 "$($user.SMTPaddress),yes" | out-file smtp-yes.csv -append
 }
 else
 {
 #NOT Found...
 "$($user.SMTPaddress),$($user.samaccountname),no"| out-file smtp-no.csv -append
 }
 }