Microsoft Exchange, Powershell, AD, MOM...

14 Kasım 2007 Çarşamba

Watching Emc Xtender's Mailbox Size with PowerShell

Exchange archiving system works perfectly after it's enabled. Archiving is controlled database-based, so you can choose which mail databases to be archived in a storage group. Or incase you want to use archiving for every database at Exchange organization you can easily make it happen by creating a system policy that includes all databases and specify the archive mailbox user.

After enabling that kind of configuration copy of each email transaction is delivered to the mailbox of this archiving user. This is where archiving systems like Xtender joins the game. This archiving systems listens this mailbox and collects each email in their own storage system for future use. With this you can be sure archiving user's mailbox will not be over-sized. I know an Exchange system with this user has a mailbox of nearly 200GB in size because of a problem in archiving server. As you can guess after that trouble had just begin for Exchange admins;)

So it's obvious that this kind of servers and services must be watched closely. You can do it easily with Microsoft Operations Manager but now we will do it with (of course) PowerShell!!



There are two variables in this code; one is the name of the exchange server holding the mailbox of archiving user and the other is the name of the archiving user. Also you can customize the threshold that when an alert will be generated..



$xtender= gwmi -ComputerName exchange_server -namespace root\MicrosoftExchangev2 -Query "Select * from Exchange_Mailbox" | where {$_.MailboxDisplayName -eq "name_of_archiving_user"}
[int]$size=$xtender.size
$totalitems=$xtender.totalitems
if($size -gt 76800)
{
$log="Xtender Critical! Size:$($size /1024)MB***By Number:$totalitems***$(get-date)"
c:\ps\sendsms.ps1 90555255xxxx "$log"
c:\ps\sendsms.ps1 90555255xxxx "$log"
c:\ps\sendsms.ps1 90555255xxxx "$log"
add-content -path "c:\ps\log.txt" -value $log
}
else
{
$log="Xtender OK! Size:$($size /1024)MB***By Number:$totalitems***$(get-date)"
add-content -path "c:\ps\log.txt" -value $log
}



First WMI is used to get information from Exchange by means of the mailbox name. To check other available members of the object by piping the object with "get-member" Here is how you can do it:



PS C:\ps> $xtender= gwmi -ComputerName exc01 -namespace root\MicrosoftExchangev2 -Query "Select * from Exchange_Mailbox"
| where {$_.MailboxDisplayName -eq "emcexadmin"}
PS C:\ps> $xtender | get-member


TypeName: System.Management.ManagementObject#root\MicrosoftExchangev2\Exchange_Mailbox

Name MemberType Definition
---- ---------- ----------
Purge Method System.Management.ManagementBaseObject Purge()
Reconnect Method System.Management.ManagementBaseObject Reconnect(System.String UserLogonName)
AssocContentCount Property System.UInt32 AssocContentCount {get;set;}
Caption Property System.String Caption {get;set;}
DateDiscoveredAbsentInDS Property System.String DateDiscoveredAbsentInDS {get;set;}
DeletedMessageSizeExtended Property System.UInt64 DeletedMessageSizeExtended {get;set;}
Description Property System.String Description {get;set;}
InstallDate Property System.String InstallDate {get;set;}
LastLoggedOnUserAccount Property System.String LastLoggedOnUserAccount {get;set;}
LastLogoffTime Property System.String LastLogoffTime {get;set;}
LastLogonTime Property System.String LastLogonTime {get;set;}
LegacyDN Property System.String LegacyDN {get;set;}
MailboxDisplayName Property System.String MailboxDisplayName {get;set;}
MailboxGUID Property System.String MailboxGUID {get;set;}
Name Property System.String Name {get;set;}
ServerName Property System.String ServerName {get;set;}
Size Property System.UInt64 Size {get;set;}
Status Property System.String Status {get;set;}
StorageGroupName Property System.String StorageGroupName {get;set;}
StorageLimitInfo Property System.UInt32 StorageLimitInfo {get;set;}
StoreName Property System.String StoreName {get;set;}
TotalItems Property System.UInt32 TotalItems {get;set;}
__CLASS Property System.String __CLASS {get;set;}
__DERIVATION Property System.String[] __DERIVATION {get;set;}
__DYNASTY Property System.String __DYNASTY {get;set;}
__GENUS Property System.Int32 __GENUS {get;set;}
__NAMESPACE Property System.String __NAMESPACE {get;set;}
__PATH Property System.String __PATH {get;set;}
__PROPERTY_COUNT Property System.Int32 __PROPERTY_COUNT {get;set;}
__RELPATH Property System.String __RELPATH {get;set;}
__SERVER Property System.String __SERVER {get;set;}
__SUPERCLASS Property System.String __SUPERCLASS {get;set;}
ConvertFromDateTime ScriptMethod System.Object ConvertFromDateTime();
ConvertToDateTime ScriptMethod System.Object ConvertToDateTime();
Delete ScriptMethod System.Object Delete();
GetType ScriptMethod System.Object GetType();
Put ScriptMethod System.Object Put();



After getting the size of the mailbox, we compare it with our threshold value (in our case it's 75MB). If mailbox size is greater than the threshold a warning message will be logged in c:\ps\log.txt file and this log will be passed to another powershell script to send sms to the admin's cell numbers. In this case log included several things:

1. A critical warning

2. Size of the mailbox

3. The number of mails in mailbox

4. Time of the day



You can schedule this ps1 script easily with Windows Scheduled Tasks. In our case it's created to run this script at every 10 minutes. But it will be annoying if you are also working with desktop of the scheduled task enabled computer. What you will see is the poping up of a powershell screen at every 10 minutes. To avoid from this situation a vbs script is used to hide and execute powershell script. Here is the code:



Dim objShell,objFSO,objFile

Set objShell=CreateObject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
strPath="C:\ps\Get-Xtender.ps1"


If objFSO.FileExists(strPath) Then

set objFile=objFSO.GetFile(strPath)
strCMD="powershell -nologo -command " & Chr(34) & "&{" &_
objFile.ShortPath & "}" & Chr(34)
objShell.Run strCMD,0

Else
WScript.Echo "Failed to find " & strPath
WScript.Quit
End If



So to summarize what we have:

1. A .vbs file to start the ps script without pop-up

2. A .ps1 script to watch the mailbox size

3. A .ps1 script to send SMS (not explained here)

4. Windows Scheduled Tasks to start .vbs file at every 10 minutes



Any comment is welcomed! As always it's probably not the best way to do it;) Enjoy!!

Hiç yorum yok: