Mailbox Move Script Verification (Full Version)

All Forums >> [Microsoft Exchange 2010] >> General



Message


MunishTaneja -> Mailbox Move Script Verification (25.Feb.2015 3:23:26 AM)

Hello All, Wanted to have below script verified which moves hidden and disabled mailboxes from one DB to another.


#########################################################################

$SourceDB = Read-Host "Enter Name of Source Database: "

$TargetDB = Read-Host "Enter Name of Target Database: "

Get-Mailbox | where-object { ($_.Database -eq '$SourceDB') -AND ($_.HiddenFromAddressListsEnabled -eq $True) -AND ($_.UserAccountControl -Match "AccountDisabled") } | export-csv C:\Test\Result.csv

$MailboxList = Get-Mailbox | where-object { ($_.Database -eq '$SourceDB') -AND ($_.HiddenFromAddressListsEnabled -eq $True) -AND ($_.UserAccountControl -Match "AccountDisabled") }

If ($MailboxList.Count -gt 0)

{
Write-Host "Number of disabled and hidden mailboxes to be moved: "

Write-Host $MailboxList.Count

$UserResponse = Read-Host "Enter Y if you want to continue mailbox moves"

If ($UserResponse -like 'Y')
{
foreach ($mailbox in $MailboxList) { New-MoveRequest -identity $mailbox -TargetDatabase $TargetDB }

} Else {

Write-Host "No mailbox moved"
}

} Else {
Write-Host "No Disabled and hidden mailbox found"
}


# Send-MailMessage -to "<To-SMTP-Address>" -from "<From-SMTP-Address> " -subject "Mailbox Move Report" -Attachments C:\Test\Result.csv -SmtpServer <Server>


$messageSubject = "Hidden and Disabled Mailbox Moves update_$datetime"
$senderName=""
$recipientName = ""
$serverIP="Relay Server FQDN"



# Utility Function goes here
function sendEmail($senderName, $RecipientName,$serverIP,$messageSubject,$messageBody)
{
$message = new-object System.Net.Mail.MailMessage($senderName, $recipientName)
$message.IsBodyHtml = $true
$message.Subject = $messageSubject
$message.body = $messageBody
$smtp = new-object Net.Mail.SmtpClient($serverIP)
$smtp.Send($message)
$message.Dispose()
}

$messageBody="<html>
<body>Mailboxes Moved from database $SourceDB to $TargetDB :<br>
</strong>
Thanks and Regards<br>
Messaging and Collaboration<br>
</body>
</html>"

sendEmail $senderName $RecipientName $serverIP $messageSubject $messageBody -Attachments C:\Test\Result.csv




Page: [1]