The Multifunctioning DBA


October 5, 2010  9:47 PM

Exchange Email Changes (filtering)



Posted by: Colin Smith
Exchange Scripting, Powershell, Scripting

Sorry for the long delay in posts but I have been moving and it is a mess. We purchased a prevously owned home and I will never do that again. New is the only way to go. But now that we are settling in and things are starting to wind down I love the house. Still a ton to do though.

Anyway back to the script. Visiting back I am working on a script that will make some big changes to our exchange environment. I actually have the script completed, tested, and have run it in production with success. So lets continue. Last we were here we validated the user and mailbox by looking at the user object in AD and comparing that with the mailbox object from Exchange. Now that we know we have the correct user and mailbox lets do something. The first thing we must do, now that we have the user object, the mailbox, and a list of all used smtp addresses, we must filter to see if this user meets the requirements for the change to be made and if so what change. For me, management had laid out a list of reasons why a mailbox would not be modified at all and why a mailbox might only have an alias added and not have the primary smtp address updated.

for example, if a user had the company field in AD set to Contoso then I might only add an alias but not change that users primary address. Or say a user has a current primary of @ms.com I might not make any changes at all. In order to do this we just need to grab the properties that we would like to filter against. Once we have those I just used if statements and then set an exclusion flag. Once the Exclusion flag has been set then I know what actions to take or not take on the mailbox.

Like this.

if (($department -eq “MS”) -or ($department -eq “Microsoft”) -or ($department -eq “Apple”))
{
$script:exclusion = 1
}

So you can see that if the users department field is equal to any of those that I set the exclusion flag to 1. Now I know what I need to do with this users mailbox and I can act appropriately.

Now that we now how to act next time we will look at how to do that.

August 30, 2010  10:00 AM

Exchange Email Changes (Users meet Mialboxes)



Posted by: Colin Smith
Exchange Scripting, Powershell, Scripting

Now that I have both the users stored in an array and the mailboxes stored in another array it is time to start making sure that I am working with a mailbox and a user account that match up. I do not want to look at my user account and Johns Mailbox and start making changes based on what I find in those two accounts that do not affect the same account. So here is what I did. It is really very simple and I will be adding more to this later for filtering of accounts and decision making. For now though here is the basics of how to make sure that the accounts are matching.

foreach($mailbox in $mailboxes)

{

$exsam = $mailbox.SamAccountName

foreach ($user in $users)

{

$adsam = $user.SamAccountName

if ($exsam -eq $adsam)

{

Echo “We have a match”

}

}

So I first get the samaccountname from Exchange and then I do the same for AD. Once I find that the Sam Names are the same I know that I have a match. That simple.


August 29, 2010  8:00 PM

Exchange Email Changes (Users)



Posted by: Colin Smith
Automation, Exchange Scripting, Powershell, Scripting

Last time we went through and got a list of all the mailboxes and out put all smtp addreses to $comparefile. This time we need to get all of the ad records that are associated with the same OU. Now to do this you need the quest ad tools. At least that is how I did it. So here we go, this is pretty easy.

$users = get-qaduser -service ms.contoso.microsoft.com -resultsize 0

So that line is not to tough and here is what it does. The -service switch will tell it what OU I want it to look in and this will include all child containers from that level. -ResultSize 0 just tells it to get them all without limiting how many results I get. So this gives me a list of all the user accounts that I am going to be dealing with and these user accounts should correspond with the mailbox info that I have already gathered.


August 29, 2010  10:00 AM

Exchange Email Changes (Mailboxes)



Posted by: Colin Smith
Exchange, Exchange Scripting, Powershell, Scripting

So lets dive into some of the code in order to get this thing done. This post will be in multiple parts since I actually am still not done writing the code. I have done the majority of it at this time and can start sharing thought. So one thing that you need to know is that I am working on this for a child domain in the forrest. Today I am going to talk about how to get the mailbox information out of exchange so we can start comparing and testing. I certainly do not want to get mailbox information for the entire Forrest of mailboxes. That would be way to many and I have no need to gather all that information. In order to get the information on the mailboxes that I am concerned with I did the following.

$mailboxes = get-mailbox -OrganizationalUnit ms.contoso.microsoft.com -ResultSize unlimited |where{$_.recipienttypedetails -eq “UserMailBox”

with my actual OU information of course. Now that will go get all the mailbox information from that OU and store it all in $mailboxes. The | where works so that I am ot gathering any roommailboxes so things like calendars and public folders are not going to be gathered into this list.  Next I figured that I wanted to output a list of all smtp address that are used to a file so I can compare addresses that I am creating to addresses that are already being used. For that I did the following loop.

$comparefile = c:\compare.txt

foreach($mailbox in $mailboxes)\

{

$smtpaddresses = $mailbox.emailaddresses | where {$_.prefixstring -eq “smtp”}

foreach($smtpaddress in $smtpaddresses)

{

$addstring = $smtpaddress.addressstring

$addstring >>  $comparefile

}

}

What I did is I go thru each mailbox one by one and I pull out all of the smtp type addresses, My company also has Notes type addresses and I am not concerned with those. Once I have all of the smtp addresses for that mailbox now I need to go thru all of those for each user one at a time and get the smtp string field and then output that to $comparefile.

So that will give me a txt file with every smtp address that my OU is using.


August 28, 2010  10:00 AM

Exchange Email Changes (Obstacle)



Posted by: Colin Smith
Exchange, Powershell, Scripting

I have run into a pretty big obstacle with my email change script. So right now I did some testing and I am able to assign the same smtp address to multiple people. I think it is a replication issue that I am running into and so I am not getting an error stating that a smtp address is in use when I set-mailbox. So in order to make sure that I am not going to have multiple accounts with the same address I am going to go get all the smtp addresses from every mailbox and dump that to a file. Once it is in the file I will complare any new addresses that I need to create to that list and verify that I am not duplicating. Every time I add a new address I will also have to update that file so that I can have an up to date list of what addresses are in use before I create the next address. This is not to hard to do just a step that I was hoping to avoid.


August 27, 2010  9:00 PM

Accidental DBA



Posted by: Colin Smith
SQL Server

I just spoke with a DBA that needed some help and I was happy to help because I know that I was in his shoes not long ago. Now some of the questions that he had seem scary to hear but I was that guy not long ago and if others would not have helped me then I would have had a very rough time getting to where I am today. I do not think that I am a great DBA by any means but I think that I have come a long way and I for sure have a long way to go. But being able to help out someone that is in a position that I used to be in is pretty awesome. That is a reason that I love the SQL Server community, because, most of the other DBA’s that I have spoken to feel very similar. That is why they make themselves available to people like me, they enjoy helping out. And so do I.


August 27, 2010  10:00 AM

Exchange Email Changes (Policy)



Posted by: Colin Smith
Exchange, Exchange Scripting, Powershell, Scripting

Another thing that I have found is that you are not able to change the primary smtp address for a mailbox if the mailbox has the emailaddresspolicyenabled flag set to true. Since in my case we want all uses to conform to the new standard, if the script determines that the Primary address needs to be changes I will have to set that flag to false and then make the change. I will not be changing that flag back to true because then the Primary Address will go back to what the policy thinks it should be and not what I really want it to be. Setting the $erroractionpreferece variable to “Inquire” helped me figure out that was happening. By default Powershell will let you know an error occured but will continue processing. I had output pushing to the screen to make sure that my filtering was working correctly so the errors did not stay on the screen long enough for me to see what they were. This option helped a lot.


August 26, 2010  7:00 PM

Exchange Email Changes



Posted by: Colin Smith
Exchange, Powershell

Part 2 in this series I am going to go over why a email policy would not work and why we are scripting this out.

So here is the deal, according to my Exchange admin for a policy to work all the users or mailboxes in an ou have to have that policy applied. We did not want to affect all the users in any ou and we also did not want to move AD objects into different OU’s in order to make this change. So we had to have some rules defined so that the script can look at each account and determine, what if anything, needs to be done to the account. The rules were like this, if a persons AD attribute of Company or Department meet certain criteria then we are to add an alias smtp address as well as change the format of the current primary smtp address. If a users company or department or email domain is something else then we do nothing with that account. and last if the user does not meet those exclusion rules then we add a new primary smtp address for that mailbox.

Now that we know the rules next time we can start looking at how we will need to filter out the accounts and determine what is going to be done with them.


August 26, 2010  10:00 AM

Fantasy Football



Posted by: Colin Smith
Fun, Games

Tomorrow I have my first Fantasy Football Draft. I got talked into joining a league with my fellow IT group. I enjoy watching football but I am not one to keep track of stats and even players, unless they are on a team that I really like. So I am going into my draft blind so to speak and will probably let most of my picks be picked for me by the computer. I figure that way at least the computer knows the numbers on all the players and should get me some good picks. I just hope that I do not come in last this season and perhaps I will get more into it and play for real next season. Just want to test the waters for now.


August 25, 2010  7:13 PM

Powershell Script to modify thousands of email records



Posted by: Colin Smith
Automation, Exchange, Powershell, Scripting

Like I said I have been tasked with a project to make thousands of modifications to our email addresses at my company. The rules are pretty complex and the Exchange Admin said that because it is not really a blanket thing that a policy will not help us. Good news for me though, now I get to do a powershell script that will determine who needs what changes if any and apply the changes.  First thing I needed to do was get the exchange management tools installed on my workstation. I did not want to be writing my code in notepad or something on the server that has the tools installed. I want to use my IDE and have access to all the cmd-lets that I need. In this case that is the exchange tools and the Quest AD cmd-lets. You can get Exchange stuff here and the Quest stuff here. Then I had to make sure that I could manage the exchange objects. Both gather information and modify when I need to. I will continue this series later. First get everything installed and we will go from there.


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: