Sunday, October 2, 2011

My Exchange Powershells

Grant a user calender permission Exchange 2010
[PS] C:\>Add-MailboxFolderPermission amalik@elgendi.com:\Calendar -User skamel@elgendi.com -AccessRights editor


RunspaceId : 23325030-1dac-4fae-9c97-75380d4b7f2e
FolderName : Calendar
User : Sonia Kamel
AccessRights : {Editor}
Identity : SSonia Kamel Blablabla
IsValid : True


[PS] C:\>Add-MailboxFolderPermission amalik@elgendi.com:\Calendar -User pPoPs@elgendi.com -AccessRights editor


RunspaceId : 23325030-1dac-4fae-9c97-75380d4b7f2e
FolderName : Calendar
User : Paul PoPs
AccessRights : {Editor}
Identity : Paul Pops Blablabla
IsValid : True

------------------------------------------------------------------------------------------------------------

How to delete E-mail from all Mailboxes

In Exchange 2010 till Sp1

Get-Mailbox –Database ABC-3GB | Export-Mailbox -Identity asabry@elgendi.com –SubjectKeyWorks "Good Morning" –SenderKeyWorks "Ahmed Sabry" -DeleteContent


------------------------------------------------------------------------------------------------------------



Exchange 2010 powershell - get messages sent / received:

Get-MessageTrackingLog -recipient “123@domain.com” -eventID send -Start “05/01/2011 1:00AM” -End “06/23/2011 1:00am”
| Select timestamp,recipients,messagesubject




------------------------------------------------------------------------------------------------------------



In Exchange 2010 SP2
Search-Mailbox -Identity "Ahmed Sabry" -SearchQuery 'Subject:"Remove CMDLET"' -DeleteContent
I didnt like it as I can not specify the sender parameter, it deleted 5 messages , I was willing to delete only 1



 Message Tracking Results using Powershell

Get-MessageTrackingLog -Start "10/02/2011 00:00AM" -Sender "rajawi@ABC.com.it" > I:\test\rajawi2Oct.txt

------------------------------------------------------------------------------------------------------------

Get Exchange Database users Mailbox Size

Get-MailboxStatistics -Database K100MB | Sort-Object TotalItemSize -Descending | ft DisplayName,TotalItemSize,ItemCount > C:\Temp\Exchange\K100MB.txt


------------------------------------------------------------------------------------------------------------


Get Exchange DB & Log file locations:
Get-MailboxDatabase -Status | select ServerName,Name,DatabaseSize,EdbFilePath,LogFolderPath


------------------------------------------------------------------------------------------------------------


Quick checkup commands  :


test-replicationhealth
Get-MailboxDatabaseCopyStatus    :  ContentIndex State failed for “ABC-MB-01”
Test-ServiceHealth -Server  ABC-MB-02
Get-Queue -ServerABC-MB-02 | FL
Test-Mailflow ABC-MB-02 -TargetMailboxServer ABC-MB-01


------------------------------------------------------------------------------------------------------------

Export Mailbox command:

First grant the permission:

New-ManagementRoleAssignment -Role "Mailbox Import Export" -User aelgendi

Second export the Mailbox:
New-MailboxExportRequest -Mailbox "mquddus@abc.com.kw" -FilePath "\\10.7.1.42\OLpst\AbboITSMail.pst"

if you got an error you may need to clean the Database.

Get-Mailboxdatabase | Clean-MailboxDatabase

you can list disconnected by Databse:
Get-MailboxStatistics -Database ABC_DB | Where { $_.DisconnectReason -eq "SoftDeleted" -or $_.DisconnectReason -eq "Disabled" } | Format-List LegacyDN, DisplayName, MailboxGUID, DisconnectReason


=====================================================================
Get list of users by GB:
***
Get-MailboxStatistics -Server ABC-mb-01 | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –

Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (GB)”;expression=

{$_.TotalItemSize.Value.ToGB()}},@{label=”Items”;expression={$_.ItemCount}},@{label=”Storage Limit”;expression=

{$_.StorageLimitStatus}} -auto > C:\PShellOutputs\sMailboxStatisticsREPORT.txt

Get list of users by MB:
***
Get-MailboxStatistics -Server ABC-mb-01 | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –

Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression=

{$_.TotalItemSize.Value.ToMB()}},@{label=”Items”;expression={$_.ItemCount}},@{label=”Storage Limit”;expression=

{$_.StorageLimitStatus}} -auto > C:\PShellOutputs\sMailboxStatisticsREPORT.txt


If Mailbox is not appearing in disconnecrted mailbox:
Get-Mailboxdatabase | Clean-MailboxDatabase


****Determining Free Space in an Exchange 2010 Mailbox Database
Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto


** Top 20 Mailbox in Size:
Get-Mailbox -database "ABC_100MB" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_100MB.txt


Get-Mailbox -database "ABC_500MB" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_500MB.txt


Get-Mailbox -database "ABC_UNLIMITED" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_UNLIMITED.txt


Get-Mailbox -database "ABC_1GB" -ResultSize Unlimited| Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name="MailboxSize";exp={$_.totalitemsize}} -first 20 > c:\PShellOutputs\ABC_1GB.txt

==========================================================================

Migrating users to new Mailbox Database , Zero down time:

1. Assign two new drives to the active server one for DB and one for Log
2. Create a new database and point to the new drives
3. Change the Database logging level to ‘Circular logging’ on the new database
4. Move the users from KFH_1GB to the new database
5. After all the users are moved delete the old database
6. Remove the ‘circular logging’ from the new database
7. Reconfigure the drive letters on the passive node to match the new DB and log drives
8. Add the new database copy to the passive node


===========================================================
After NLB configuration you may need to run this command if the servers are not responding:
 netsh interface ipv4 set interface "NLB" forwarding=enabled