Adding Mail enabled public folder as the member of Distribution list

Some times you may wanted to add mail enabled public folder as the member of Distrubution list and you wanted to send copy of mail to PF which is sent to distrubution list.  For this you may need to add mail enabled public folder as the member of the DL

Its not possible add public folder as members of DL in Exchange 2003. This can be only done from Exchagne 2007.
Throught Exchange 2007 you can add both throught Exchange management console and Powershell command

Powershell command
Add-DistributionGroupMember  -Identity “DLName”  -Member “Email address”

Exchange Management console
Expand Recipient Configuration -> Distibution Group -> find the requied DL -> Add the same

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

Deleted Mailbox not appearing in Disconnected mailbox in Exchange 2007

Deleted mailboxes will appear in disconnected mailbox list, but it will not reflect immediately. We have to wait for online maintenance to run and complete.

If we accidentally delete mailbox and if we wanted to reconnect it back then we may not be able to find it Disconnected Mailbox. We have run Clean-MailboxDatabase to get the deleted mailbox.

Eg.

Clean-MailboxDatabase \servername\SGName\Store
Cleaning Database of Individual Store

Get-Mailboxdatabase | Clean-MailboxDatabase
Cleans all the database in the Organization

Get-Mailboxdatabase | Where{ $_.Server –eq “<servername>”}| clean-MailboxDatabase
Cleans all the database in the specific store

Get-Mailboxdaatabase | Where{ $_.Name –eq “<DatabaseName>”}| clean-MailboxDatabase
Cleans all the Database which matches the specific name given in Databasename

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 
}

Activeroles Quest Management Powershell to check User account Active or Disabled

You can download Active roles Quest Management shell from the below mentioned link.

http://www.quest.com/powershell/activeroles-server.aspx

Commands to check if mailbox is active or disabled

Get-QADUser <username> -enabled              

Will get the result if acount in active

Get-QADUser <username> -disabled                

Will get result if account is disabled

Get-QADUser  -Enabled       

Will get  all the enabled in the Active Directory

Get-QADUser  -Disabled      

Will get all the disabled users in the Active Directory

get-content “C:\users.txt” | Get-QADUser -enabled | select Email 

Will get list of all active users email address from the given input users

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
                }
 }

Difference Between Disable-Mailbox and Remove-mailbox

Disable-Mailbox : It will detach the mailbox(removed exchange attributes) from the Ad user objects and adds detached mailbox to the disconnected mailbox list

Eg:  Disable-Mailbox username

Delete-Mailbox: It will delete Mailbox and Ad object and moved to Disconnected mailbox list.  Disconnected mailbox will exists until Deletion settings set in the mailbox store. Any time we can go and reconnect to the disconnected the mailbox.

Eg. Remove-Mailbox username -Permanent

-Permanent option will permanently deletes the mailbox and with out moving to Disconnected mailbox list.

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)