Powershell to get the list of Disconnected mailbox in the Exchange Server

If we delete a user account then it will automatically disconnects mailbox from the account and adds to Disconnected Mailbox list. Mailbox  will be listed until retention period of 30 days

Get-MailboxStatistics -server <servername> | where { $_.DisconnectDate -ne $null } | select DisplayName,MailboxGuid,Database,DisconnectDate

Gets the list of Disconnected mailbox in the specified Exchange 2007 Server

 

Get-MailboxStatistics  | where { $_.DisconnectDate -ne $null } | select DisplayName,MailboxGuid,Database,DisconnectDate

Gets the list of Disconnected mailbox on the Exchange 2007  maibox server where you are running this command

Recovering Deleted User Ad account throught Active Directory powershell

We can recover any Active Directory deleted object with in the Tombstone period.
Tombstone lifetime can be found in active directory using below steps

• Load the ADSIEdit snap-in by navigating to start menu, programs, Windows 2000 Support Tools, Tools, ADSI Edit, or simply type adsiedit.msc at the run command.
• Navigate down to CN=Directory Service, through Configuration, CN=Configuration,DC=domainName,DC=com, CN=Services, CN=Windows NT, right-click and choose properties. 
• scroll down to tombstoneLifetime. This will have Tombstone period

Get-QADUser -Tombstone

Will get the list of user accounts which are Deleted and residing in Tombstone

  

Get-QADUser -Tombstone <name> |restore-QADDeletedObject

Will restore the user object in to the OU LOSTANDFOUND

  

Get-QADUser -Tombstone -LastKnownParent ‘<DN of container>’
Restores all user accounts that were deleted from a particular container to OU LOSTANDFOUND.

 

 Get-QADUser –Tombstone –LastChangedOn (get-date -year 2008 -month 9 -day 1)

Restores all user accounts that were deleted on September 1, 2008

 

Get-QADUser –Tombstone  <username> | fl

Gives the complete details of the -Tombstone account which can help in finding detained information of the Tombstoned account

Powershell to find the size of Spam Mails folders in the Exchange mailbox

Below script can be used to find the size of spam  Mails folder in the User mailbox for the given list of users. Export list of users from the server throught below command and input into the Name.txt and Execute 

Get-mailbox | Where{$_.Servername -eq “Servername”} | select-object Alias > c:\Names.txt

 
$UserList = Get-Content “C:\Names.txt”
foreach($user in $UserList)
{
     $Spamsize = get-mailboxfolderstatistics $user | Where {$_.Name -match “Spam”}  | select  FolderAndSubfolderSize
     $output = $user + ” ” + $spamsize.FolderAndSubfolderSize/1mb
     Write-output $output 
}

Powershell to get top 100 mailboxes in the Exchange 2007 server

Below Powershell script gets you the top 100 mailboxes from an Exchange 2007 server in the sorted format

Get-MailboxStatistics |sort totalitemsize -des | select-object Displayname, ItemCount,@{name=’TotalItemSize(MB)’;expression={$_.totalitemsize/1MB}}  -first 100

Top address 100 mailbox in the specific Exchange server. You can always modify the count as per your requirement. -first xxx has to modified to get the expected count result.

$MailboxServer = <servername>

Get-MailboxStatistics | ?{$_.ServerName -eq $MailboxServer }|sort totalitemsize -des | select-object Displayname, ItemCount,@{name=’TotalItemSize(MB)’;expression={$_.totalitemsize/1MB}}  -first 100

 

Below powershell will get the list of top 10 mailbox from the specific Exchange database or Store

$database = <database>
Get-MailboxStatistics | ?{$_.Database -eq $database}|sort totalitemsize -des | select-object Displayname, ItemCount,@{name=’TotalItemSize(MB)’;expression={$_.totalitemsize/1MB}}  -first 10

Powershell to Get the list of Live Servers

Below Powershell script take list of servers as input and it pings the server, if servers replies then it will writes Live server name in C:\scripts\serversRunning.txt.

 $ServerList = Get-Content “C:\scripts\Serverlist.txt”
foreach($Server in $ServerList)
{
                 $Server
                $ping = New-Object System.Net.NetworkInformation.Ping
                $reply = $null
                $Server = $Server.trim()
                $reply = $ping.Send($Server)
                if ($reply.status -eq “Success”) {
                $out = $Server | out-File “C:\scripts\serversRunning.txt” -Append
                } else {
                        $Server | out-File “C:\scripts\serversnotpinging.txt” -Append
                }
 }

Powershell script to send mail

Below Powershell script can be used to send mail using SMTP server. It reads every line from the text file and adds to the body of the email and sent it.

  $emailFrom = “Fromaddress”
 $emailTo = “Toaddress”
 $sub = Date
 $subject = “Subject ” + $sub
 $UserList = Get-Content “C:\Details.txt”
 $body = “”
 foreach($user in $UserList)
  {
     $body = $body + $user + “`n” # ‘n represents the new line escape sequence
  }
 $smtpServer = “SMTPServer”
 $smtp = new-object Net.Mail.SmtpClient($smtpServer)
 $smtp.Send($emailFrom, $emailTo, $subject, $body)

Setting Mailbox Quota Limits in Exchange 2007 throught Powershell

Command to set MailBox Quota limits on all the stores in Exchange 2007  environment.

Get-Mailboxdatabase | Set-mailboxdatabase -ProhibitSendReceiveQuota 2GB -ProhibitSendQuota 1GB -IssueWarningQuota 900MB

 

Command to set Mailbox Quota limits on all the stores on the specific exchange server

Get-Mailboxdatabase -server $Server | Set-mailboxdatabase -ProhibitSendReceiveQuota 2GB -ProhibitSendQuota 1GB -IssueWarningQuota 900MB

 

Command to set Mailbox Quota limits on all the stores on the specific exchange server except on the specific store

$Server =<ExchagneServername>
$DB =<Databasename>
Get-mailboxdatabase -server $Server | Where {$_.Name -ne $DB} | Set-mailboxdatabase -ProhibitSendReceiveQuota 2GB -ProhibitSendQuota 1GB -IssueWarningQuota 900M
 

 

Powershell Command to set Mailbox Quota limits on a specific store in a given Exchagne 2007 server

$Server =<ExchagneServername>
$DB =<Databasename>
Get-mailboxdatabase -server $Server | Where {$_.Name -eq $DB} | Set-mailboxdatabase -ProhibitSendReceiveQuota 2GB -ProhibitSendQuota 1GB -IssueWarningQuota 900M

Powershell command to set Exchange WarningMailbox, ProhibitSendMailbox, ProhibitSendReceiveMailbox Warning Messages for Exchange 2007

Please find the below commands to set Custom Quota Messages for Warning, ProhibitSendMailbox and ProhibitSendReceiveMailBox, Just change the require custom message and apply the same.

New-SystemMessage -QuotaMessageType WarningMailbox -Language EN -Text “Your Custom Message”

New-SystemMessage -QuotaMessageType ProhibitSendMailbox -Language EN -Text “Your Custom Message”

New-SystemMessage -QuotaMessageType ProhibitSendReceiveMailBox -Language EN -Text “Your Custom Message”