Exchange Exchange
A community dedicated to Exchange and related technology.
Doing things with arrays (of Exchange databases) - and no, not disk arrays. Collection arrays.

One of my customers has 18 information stores per server, and our support folks wanted online maintenance to start on a staggered schedule, with six dbs starting online maintenance at 11 pm, another 6 starting at midnight, and the last 6 starting at 1 am. Simple enough to do in the GUI, but I have four mailbox servers, and that's a lot of boring clicking. I don't like clicking.

So first, I needed to create an array of the databases. For simplicity's sake, I'm only going to show you how to do this by using an example set of six databases. In case it's not clear, you use the Exchange Management Shell to do the following steps. Note that the things you do in powershell are bolded here.

$mbdbs = "MBX01\SG01-DB01","MBX01\SG02-DB01","MBX01\SG03-DB01","MBX01\SG04-DB01","MBX01\SG05-DB01","MBX01\SG06-DB01"

I could have identified different servers, or all servers and all databases in the array. But we're keeping it simple here. Note that I did not call out the storage groups above - there's no need to. Now if all databases are named "First Mailbox Database", then you'd need to call out the SG name as well. I couldn't simply use the db names, as the db names are duplicated across the servers. If all of my dbs had different names, that would have made things a little simpler.

Next, I need to identify the servers in batches. Since I've changed the set of dbs from the 18 that I have in reality to the 6 I'm using here, we'll set online maintenance for groups of two, not six, databases at a time. There are a couple things I want to point out here, because if you're not familiar with how you can pull information from an array in powershell, then the below may seem like mumbo jumbo...

What we're doing is:

ForEach --> self-explanatory - for each item I'm calling

($db in $mdbs[0..1]) --> Wait! I didn't identify the $db variable anywhere. But hey, powershell is smart enough to know that, when presented the way I've presented it, an undeclared variable is an item being called. And then there are those funky brackets at the end. WTF? Well, what I'm doing with the numbers in the brackets is calling the first items in the array (note that arrays are weird, and the numbering of items within an array starts at 0, not 1). Because my example is only calling two dbs at a time, I could have used [0,1] in the brackets, but I wanted to show that the .. (dot dot) annotation between the numbers within the brackets tells powershell to call items 0 and 1 in the array. If it were [0..5] in the array (which it was in the original syntax I used), the first six items in the array would have been called.

{set-mailboxdatabase $db -blah --> here's the important stuff. We've gathered our databases, we've identified which ones we want to take action on, and now we're rolling with it. So for dbs 0 and 1 in the array ("MBX01\SG01-DB01","MBX01\SG02-DB01"), set the mailbox database's -blah. My example uses online maintenance, but whatever. It's getting the syntax right that's key. So here are the additional commands I'd use to complete my task:

ForEach ($db in $mbdbs[0..1]) {set-mailboxdatabase $db -maintenanceSchedule "Mon.11:00 PM-Tue.4:00 AM", "Tue.11:00 PM-Wed.4:00 AM", "Wed.11:00 PM-Thursday.4:00 AM", "Thursday.11:00 PM-Fri.4:00 AM", "Fri.11:00 PM-Sat.4:00 AM", "Sat.11:00 PM-Sun.11:00 PM", "Sun.11:00 PM-Mon.4:00 AM"}

ForEach ($db in $mbdbs[2..3]) {set-mailboxdatabase $db -maintenanceSchedule "Mon.12:00 PM-Tue.5:00 AM", "Tue.12:00 PM-Wed.5:00 AM", "Wed.12:00 PM-Thursday.5:00 AM", "Thursday.12:00 PM-Fri.5:00 AM", "Fri.12:00 PM-Sat.5:00 AM", "Sat.12:00 PM-Sun.12:00 PM", "Sun.12:00 PM-Mon.5:00 AM"}

ForEach ($db in $mbdbs[4..5]) {set-mailboxdatabase $db -maintenanceSchedule "Mon.1:00 AM-Mon.6:00 AM", "Tue.1:00 AM-Tue.6:00 AM", "Wed.1:00 AM-Wed.6:00 AM", "Thursday.1:00 AM-Thursday.6:00 AM", "Fri.1:00 AM-Fri.6:00 AM", "Sat.1:00 AM-Sat.6:00 AM", "Sun.1:00 AM-Sun.6:00 AM"}

For some reason, I originally thought that my problem was that I needed commas to appear when I called the array (to see what I mean, create an array, say $fish = carp,cod,trout,shad. Next, call the array by typing $fish. You should get a list as such, which is not what I thought I wanted. But it is, actually, okay:

carp

cod

trout

shad

Except the list will not have double spacing. :)

But anyway, I thought that my commands were failing because I needed a comma instead of a line break between the items in the array. Not so. When I tracked down the proper syntax (which I've shown you above), I felt like a big dork. But not too big a dork to not share the information. :)

Questions?


Posted Tue, Dec 1 2009 1:40 PM by Missy Koslosky
© 2003-2009 NamedPipes Consulting. All other company and product names are property of their owners.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems