• RSS
  • Twitter
  • FaceBook

Exchange Server Forums

Forums | Register | Login | My Profile | Inbox | RSS RSS icon | My Subscription | My Forums | Address Book | Member List | Search | FAQ | Ticket List | Log Out

Mailbox Move Script Verification

Users viewing this topic: none

Logged in as: Guest
  Printable Version
All Forums >> [Microsoft Exchange 2010] >> General >> Mailbox Move Script Verification Page: [1]
Login
Message << Older Topic   Newer Topic >>
Mailbox Move Script Verification - 25.Feb.2015 3:23:26 AM   
MunishTaneja

 

Posts: 1
Joined: 25.Feb.2015
Status: offline
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
Post #: 1

Page:   [1] << Older Topic    Newer Topic >>
All Forums >> [Microsoft Exchange 2010] >> General >> Mailbox Move Script Verification Page: [1]
Jump to:

New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Follow TechGenix on Twitter