#replace ServerName with the name of the Exchange Server
#write the list of database to an array
$mbdb = get-mailboxdatabase -Server ServerName| Where {($_.StorageGroupName -notlike "RSG*")}
#Sort the list of databases
$mbdb = $mbdb | Sort-Object
This will write out an array of databases on the specified server to the $mbdb variable.$x = 0
$i = 0
We will use the $i counter to count how many database are in the array and then increment through them one at a time.for ($i = 0; $i -le ($mbdb.Length -1); $i +=1)
Now for the meat of the code. From this point, you will increment the other counter ($x). This will be the revolving counter that determines which description to give the database. When it gets to 3, you will see that after it sets the description, it will set the counter back to 0 for the next round.$x += 1
$DN = $mbdb[$i].DistinguishedName
Switch ($x)
{
1 {
$Desc = "A"
}
2 {
$Desc = "B"
}
3 {
$Desc = "C"
$x = 0
}
}
Once we have the description, we will then set it using ADSI. To do this we will create an LDAP connection to the distinguished name of the database and write the returned object to an array called $addb. This will have all of the AD attributes in it. We only care about the description attribute so we will set it to the description our code has selected for us and then save it using the SetInfo() parameter. It looks like this:$addb = [adsi]"LDAP://$DN"
$addb.Description = $Desc
$addb.SetInfo()
$mbdb = get-mailboxdatabase -Server ServerName| Where {($_.StorageGroupName -notlike "RSG*")}
$mbdb = $mbdb | Sort-Object
$x = 0
$i = 0
for ($i = 0; $i -le ($mbdb.Length -1); $i +=1)
{
$x += 1
$DN = $mbdb[$i].DistinguishedName
Switch ($x)
{
1 {
$Desc = "A"
}
2 {
$Desc = "B"
}
3 {
$Desc = "C"
$x = 0
}
}
$addb = [adsi]"LDAP://$DN"
$addb.Description = $Desc
$addb.SetInfo()
}
How to move the mailboxes to the appropriate stores based on their size and the store's description will be shown in another article.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)