Setting Mailbox Limits by OU and by Group

Originally published November 18, 2004

 

It's a common request to set mailbox limits for all the users in a particular OU or for all the users in a group.

That functionality is not built-in to Exchange.

The following script shows you how to do both and hopefully, is fairly self-explanatory.

Option Explicit

Const OU_HOSTING = "OU=Hosting"  ' the OU where I put customer OU's
Const ExchServer = "ORANGE"  ' the exchange server whose default mailbox store I'll use
Const bDebug     = False  ' verbose output

Const iStorageQuota  = 90000  '  90,000 KB = 90 MB
Const iOverQuota     = 95000            '  95,000 KB = 95 MB
Const iOverHardQuota = 100000           ' 100,000 KB = 100 MB

Dim strNamingContext, strConfigContext
Dim strOrgDN
Dim strNetBIOSDomain, strNetBIOSComputer
Dim bReport    ' report on current (or after mods)
Dim bMod    ' make modifications as above

Sub GetSystemInfo
 Dim objSystemInfo, objWSHNetwork, objRootDSE

 Set objRootDSE = GetObject ("LDAP://RootDSE")
 strNamingContext = objRootDSE.Get ("defaultNamingContext")
 strConfigContext = objRootDSE.Get ("configurationNamingContext")
 Set objRootDSE = Nothing

 ' get the NetBIOS domain name
 Set objSystemInfo = CreateObject ("ADSystemInfo")
 strNetBIOSDomain = objSystemInfo.DomainShortName
 Set objSystemInfo = Nothing

 ' get the NetBIOS computer name
 Set objWSHNetwork = CreateObject ("WScript.Network")
 strNetBIOSComputer = objWSHNetwork.ComputerName
 Set objWSHNetwork = Nothing
End Sub

Sub ProcessHostingOU
 Dim objHosting, objOU

 Set objHosting = GetObject ("LDAP://" & OU_HOSTING & "," & strNamingContext)

 objHosting.Filter = Array ("organizationalUnit")

 For Each objOU in objHosting
  'wscript.echo "Name = " & objOU.Name & " ADSPath = " & objOU.ADSPath
  Call ProcessUsersByOU (objOU.Name, objOU.ADSPath)
 Next

 Set objHosting = Nothing
End Sub

Sub ProcessUser (ByRef objUser)
 wscript.echo vbTab & objUser.Name
 If bMod = True Then
  If iStorageQuota = 0 And iOverQuota = 0 And iOverHardQuota = 0 Then
   ' reset to defaults
   objUser.mDBUseDefaults = True
  Else
   objUser.mDBUseDefaults        = False
   objUser.mDBStorageQuota       = iStorageQuota
   objUser.mDBOverQuotaLimit     = iOverQuota
   objUser.mDBOverHardQuotaLimit = iOverHardQuota
  End If
  objUser.SetInfo
 End If

 If bReport = True Then
  wscript.echo vbTab & vbTab & "Use mailbox store defaults: "              & objUser.mDBUseDefaults
  If objUser.mDBUseDefaults = False Then
   wscript.echo vbTab & vbTab & "Issue warning at (KB): "           & objUser.mDBStorageQuota
   wscript.echo vbTab & vbTab & "Prohibit send at (KB): "           & objUser.mDBOverQuotaLimit
   wscript.echo vbTab & vbTab & "Prohibit send & receive at (KB): " & objUser.mDBOverHardQuotaLimit
  End If
 End If
End Sub

Sub ProcessUsersByOU (ByVal strOUName, ByVal strOUADSPath)
 Dim objOU, objUser

 wscript.echo "Processing " & strOUName
 
 Set objOU = GetObject (strOUADSPath)

 objOU.Filter = Array ("user")

 For Each objUser in objOU
  wscript.echo vbTab & objUser.Name
  Call ProcessUser (objUser)
 Next

 Set objOU = Nothing
End Sub

Sub ProcessUsersByGroup (ByVal strGroupDN)
 Dim objGroup, objUser

 wscript.echo "Processing " & strGroupDN
 Set objGroup = GetObject ("LDAP://" & strGroupDN)

 For Each objUser in objGroup.Members
  wscript.echo vbTab & objUser.Name
  Call ProcessUser (objUser)
 Next
End Sub

Call GetSystemInfo

bReport = True
bMod    = False

Call ProcessHostingOU

Call ProcessUsersByGroup ("CN=Allusers@domain.com,OU=domain.com," & OU_HOSTING & "," & strNamingContext)

Published Tuesday, November 13, 2007 7:14 PM by michael
Filed under: , ,

Comments

No Comments