steelcoyot
MIS
the script has two parts.
part one goes to the root domain and extracts data from the exchange servers about storage limit policies, and then writes them to a "dictionary".
It then goes through each user account, and if they have a mailbox on one of the stores, it check the value of the storage limit and writes it to a file.
Unfortunately, it only checks accounts in the root domain, but I need both root domain accounts and child domain accounts. (there are about 20 child domains at this point.) All the exchange servers are in the root domain.
I have been running it with enterprise admin rights, so there should be no problem with the rights in the child domain
Set colNamedArguments = WScript.Arguments.Named
strOutputFile = colNamedArguments.Item("f")
strNoConOutput = colNamedArguments.Item("s")
strHelp = colNamedArguments.Item("help")
'Detect help and write help text to console
WriteHelp
Const Textmode = 1
'Get AD Path
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomainContext = objRootDSE.Get("defaultNamingContext")
'WScript.Echo "strDomainContext: " & strDomainContext '#debug remove
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
Wscript.Echo strADsPath
'Setup ADODB connection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'Modify the page size to increase or decrease number of objects retuned in the result se
objCommand.Properties("Page Size") = 1000
'Get Mailbox Stores - msExchPrivateMDB
'Execute search command to look for Organization
objCommand.CommandText = _
"<LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration," & strDomainContext & ">" & ";(&(objectClass=msExchPrivateMDB)(!objectClass=msExchPrivateMDBPolicy))" & ";distinguishedName,name,msExchPolicyList,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit" & _
";subtree"
'Execute search to get Recordset
Set objStoresRS = objCommand.Execute
'# If no mailboxe Stores found
WScript.Echo "AD Search for mailbox stores completed" '#debug remove
If objStoresRS.RecordCount = 0 Then
strOutput = strOutput & VbCrLf & "No Mailbox Stores found!"
WScript.Echo strOutput
' WScript.Quit
Else
strOutput = strOutput & VbCrLf & "Mailbox Stores found: " & objStoresRS.RecordCount
WScript.Echo strOutput '#debug remove
'Create Dictionary object here
Set objStoresDictionary = CreateObject("Scripting.Dictionary")
objStoresDictionary.CompareMode = Textmode
WScript.Echo "Dictionary Created" '#debug remove
'Enumerate Stores
While Not objStoresRS.EOF
Set objStore = GetObject("LDAP://" & objStoresRS.Fields("distinguishedName") & "")
WScript.Echo "Bound to Store: " & objStore.distinguishedName
strStoreNameDictEntry = objStore.distinguishedName 'Get Store CN for Dictionary
'Check Store for Policy
If IsArray(objStoresRS.Fields("msExchPolicyList")) Then
WScript.Echo "Store has Policy!" '#debug remove
For Each strPolicyDN In objStoresRS.Fields("msExchPolicyList").value
Set objPolicy = GetObject ("LDAP://" & strPolicyDN & "")
WScript.Echo "Policy Name: " & objPolicy.cn
'Check Policy for Quota limits
If IsEmpty(objPolicy.mDBStorageQuota) Then 'mDBOverQuotaLimit mDBOverHardQuotaLimit
WScript.Echo "Policy does not have Mailbox Quota"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Policy Mailbox Quota: " & objPolicy.mDBStorageQuota
strStoreDictEntry = strStoreDictEntry & "#" & objPolicy.mDBStorageQuota
End If
If IsEmpty(objPolicy.mDBOverQuotaLimit) Then ' mDBOverHardQuotaLimit
WScript.Echo "Policy does not have Mailbox Over Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Policy Mailbox Over Quota Limit: " & objPolicy.mDBOverQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objPolicy.mDBOverQuotaLimit
End If
If IsEmpty(objPolicy.mDBOverHardQuotaLimit) Then '
WScript.Echo "Policy does not have Mailbox Over Hard Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Policy Mailbox Over Hard Quota Limit: " & objPolicy.mDBOverHardQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objPolicy.mDBOverHardQuotaLimit
End If
'End Policy Quota Check
strStoreDictEntry = strStoreDictEntry & "#Policy" & "#" & objPolicy.cn
objStoresDictionary.Add strStoreNameDictEntry, strStoreDictEntry
' WScript.Echo "Dict count: " & objStoresDictionary.Count
Next 'Move to Next Policy
Else
WScript.Echo "#No Policy" '#debug remove
'Check Store Quotas Here
If IsEmpty(objStore.mDBStorageQuota) Then 'mDBOverQuotaLimit mDBOverHardQuotaLimit
WScript.Echo "Store does not have Mailbox Quota"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Store Mailbox Quota: " & objStore.mDBStorageQuota
strStoreDictEntry = strStoreDictEntry & "#" & objStore.mDBStorageQuota
End If
If IsEmpty(objStore.mDBOverQuotaLimit) Then ' mDBOverHardQuotaLimit
WScript.Echo "Store does not have Mailbox Over Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Store Mailbox Over Quota Limit: " & objStore.mDBOverQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objStore.mDBOverQuotaLimit
End If
If IsEmpty(objStore.mDBOverHardQuotaLimit) Then '
WScript.Echo "Store does not have Mailbox Over Hard Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Store Mailbox Over Hard Quota Limit: " & objStore.mDBOverHardQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objStore.mDBOverHardQuotaLimit
End If
'End Store Quota Check
strStoreDictEntry = strStoreDictEntry & "#Store#"
WScript.Echo "dictStoreNameDictEntry: Key:" & strStoreNameDictEntry & " - strStoreDictEntry: " & strStoreDictEntry
objStoresDictionary.Add strStoreNameDictEntry, strStoreDictEntry
End If 'End Check for Policy
' WScript.Echo "DictionaryEntry: " & strStoreDictEntry '#debug remove
WScript.Echo "Stores in Dictionary: " & objStoresDictionary.Count
strStoreNameDictEntry = Null
strStoreDictEntry = Null
WScript.Echo "----------------------"
objStoresRS.MoveNext
Wend
End If
'-----------------------------------------------------------------------------------------------------------------------------------
'Part 2 of script - checks users
'Execute search command to look for Organization
objCommand.CommandText = _
"<" & strADsPath & ">" & ";(&(objectClass=user)(homeMDB=*)(!CN=SystemMailbox{*}))" & ";distinguishedName,name,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit" & _
";subtree"
'Execute search to get Recordset
Set objUsersRS = objCommand.Execute
strOutput = strOutput & VbCrLf & strTitle & VbCrLf & "===================================="
'# If no mailboxes found
If objUsersRS.RecordCount = 0 Then
WScript.Echo "No mailboxes found!"
' WriteFile
WScript.Quit
Else
strOutput = strOutput & VbCrLf & "Mailboxes found: " & objUsersRS.RecordCount
strOutput = strOutput & VbCrLf & "--------------------------" & VbCrLf
strOutput = strOutput & "All limits are in Kilobytes (KB)" & VbCrLf
strOutput = strOutput & "User#Store#Limit#Stop Send (mDBOverQuota)#Stop Receive (mDBOverHardQuotaLimit)#Set On#Policy Name" & VbCrLf
While Not objUsersRS.EOF
'# Check if mailbox bypasses Store/Policy limits
Set objUser = GetObject("LDAP://" & objUsersRS.Fields("distinguishedName") & "")
'Get users' homeMDB
strHomeMDB = objUser.homeMDB
Set objHomeMDB = GetObject("LDAP://" & strHomeMDB & "")
strHomeMDBCn = objHomeMDB.distinguishedName
'# Check if User does not have default limits (does not bypass Store/Policy)
If objUser.mDBUseDefaults Then
strUserStatus = strUserLimit & objUser.displayName & "#"
'Check Dictionary for Store
If objStoresDictionary.Exists(strHomeMDBCn) Then
' WScript.Echo "Exists"
strToAdd =strHomeMDBCn & objStoresDictionary.Item(strHomeMDBCn)
' WScript.Echo "strToAdd: " & strToAdd
strUserStatus = strUserStatus & strToAdd
Else
WScript.Echo "Store does not exist in Dictionary"
End If
part one goes to the root domain and extracts data from the exchange servers about storage limit policies, and then writes them to a "dictionary".
It then goes through each user account, and if they have a mailbox on one of the stores, it check the value of the storage limit and writes it to a file.
Unfortunately, it only checks accounts in the root domain, but I need both root domain accounts and child domain accounts. (there are about 20 child domains at this point.) All the exchange servers are in the root domain.
I have been running it with enterprise admin rights, so there should be no problem with the rights in the child domain
Set colNamedArguments = WScript.Arguments.Named
strOutputFile = colNamedArguments.Item("f")
strNoConOutput = colNamedArguments.Item("s")
strHelp = colNamedArguments.Item("help")
'Detect help and write help text to console
WriteHelp
Const Textmode = 1
'Get AD Path
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomainContext = objRootDSE.Get("defaultNamingContext")
'WScript.Echo "strDomainContext: " & strDomainContext '#debug remove
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
Wscript.Echo strADsPath
'Setup ADODB connection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'Modify the page size to increase or decrease number of objects retuned in the result se
objCommand.Properties("Page Size") = 1000
'Get Mailbox Stores - msExchPrivateMDB
'Execute search command to look for Organization
objCommand.CommandText = _
"<LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration," & strDomainContext & ">" & ";(&(objectClass=msExchPrivateMDB)(!objectClass=msExchPrivateMDBPolicy))" & ";distinguishedName,name,msExchPolicyList,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit" & _
";subtree"
'Execute search to get Recordset
Set objStoresRS = objCommand.Execute
'# If no mailboxe Stores found
WScript.Echo "AD Search for mailbox stores completed" '#debug remove
If objStoresRS.RecordCount = 0 Then
strOutput = strOutput & VbCrLf & "No Mailbox Stores found!"
WScript.Echo strOutput
' WScript.Quit
Else
strOutput = strOutput & VbCrLf & "Mailbox Stores found: " & objStoresRS.RecordCount
WScript.Echo strOutput '#debug remove
'Create Dictionary object here
Set objStoresDictionary = CreateObject("Scripting.Dictionary")
objStoresDictionary.CompareMode = Textmode
WScript.Echo "Dictionary Created" '#debug remove
'Enumerate Stores
While Not objStoresRS.EOF
Set objStore = GetObject("LDAP://" & objStoresRS.Fields("distinguishedName") & "")
WScript.Echo "Bound to Store: " & objStore.distinguishedName
strStoreNameDictEntry = objStore.distinguishedName 'Get Store CN for Dictionary
'Check Store for Policy
If IsArray(objStoresRS.Fields("msExchPolicyList")) Then
WScript.Echo "Store has Policy!" '#debug remove
For Each strPolicyDN In objStoresRS.Fields("msExchPolicyList").value
Set objPolicy = GetObject ("LDAP://" & strPolicyDN & "")
WScript.Echo "Policy Name: " & objPolicy.cn
'Check Policy for Quota limits
If IsEmpty(objPolicy.mDBStorageQuota) Then 'mDBOverQuotaLimit mDBOverHardQuotaLimit
WScript.Echo "Policy does not have Mailbox Quota"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Policy Mailbox Quota: " & objPolicy.mDBStorageQuota
strStoreDictEntry = strStoreDictEntry & "#" & objPolicy.mDBStorageQuota
End If
If IsEmpty(objPolicy.mDBOverQuotaLimit) Then ' mDBOverHardQuotaLimit
WScript.Echo "Policy does not have Mailbox Over Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Policy Mailbox Over Quota Limit: " & objPolicy.mDBOverQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objPolicy.mDBOverQuotaLimit
End If
If IsEmpty(objPolicy.mDBOverHardQuotaLimit) Then '
WScript.Echo "Policy does not have Mailbox Over Hard Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Policy Mailbox Over Hard Quota Limit: " & objPolicy.mDBOverHardQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objPolicy.mDBOverHardQuotaLimit
End If
'End Policy Quota Check
strStoreDictEntry = strStoreDictEntry & "#Policy" & "#" & objPolicy.cn
objStoresDictionary.Add strStoreNameDictEntry, strStoreDictEntry
' WScript.Echo "Dict count: " & objStoresDictionary.Count
Next 'Move to Next Policy
Else
WScript.Echo "#No Policy" '#debug remove
'Check Store Quotas Here
If IsEmpty(objStore.mDBStorageQuota) Then 'mDBOverQuotaLimit mDBOverHardQuotaLimit
WScript.Echo "Store does not have Mailbox Quota"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Store Mailbox Quota: " & objStore.mDBStorageQuota
strStoreDictEntry = strStoreDictEntry & "#" & objStore.mDBStorageQuota
End If
If IsEmpty(objStore.mDBOverQuotaLimit) Then ' mDBOverHardQuotaLimit
WScript.Echo "Store does not have Mailbox Over Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Store Mailbox Over Quota Limit: " & objStore.mDBOverQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objStore.mDBOverQuotaLimit
End If
If IsEmpty(objStore.mDBOverHardQuotaLimit) Then '
WScript.Echo "Store does not have Mailbox Over Hard Quota Limit"
strStoreDictEntry = strStoreDictEntry & "#null"
Else
WScript.Echo "Store Mailbox Over Hard Quota Limit: " & objStore.mDBOverHardQuotaLimit
strStoreDictEntry = strStoreDictEntry & "#" & objStore.mDBOverHardQuotaLimit
End If
'End Store Quota Check
strStoreDictEntry = strStoreDictEntry & "#Store#"
WScript.Echo "dictStoreNameDictEntry: Key:" & strStoreNameDictEntry & " - strStoreDictEntry: " & strStoreDictEntry
objStoresDictionary.Add strStoreNameDictEntry, strStoreDictEntry
End If 'End Check for Policy
' WScript.Echo "DictionaryEntry: " & strStoreDictEntry '#debug remove
WScript.Echo "Stores in Dictionary: " & objStoresDictionary.Count
strStoreNameDictEntry = Null
strStoreDictEntry = Null
WScript.Echo "----------------------"
objStoresRS.MoveNext
Wend
End If
'-----------------------------------------------------------------------------------------------------------------------------------
'Part 2 of script - checks users
'Execute search command to look for Organization
objCommand.CommandText = _
"<" & strADsPath & ">" & ";(&(objectClass=user)(homeMDB=*)(!CN=SystemMailbox{*}))" & ";distinguishedName,name,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit" & _
";subtree"
'Execute search to get Recordset
Set objUsersRS = objCommand.Execute
strOutput = strOutput & VbCrLf & strTitle & VbCrLf & "===================================="
'# If no mailboxes found
If objUsersRS.RecordCount = 0 Then
WScript.Echo "No mailboxes found!"
' WriteFile
WScript.Quit
Else
strOutput = strOutput & VbCrLf & "Mailboxes found: " & objUsersRS.RecordCount
strOutput = strOutput & VbCrLf & "--------------------------" & VbCrLf
strOutput = strOutput & "All limits are in Kilobytes (KB)" & VbCrLf
strOutput = strOutput & "User#Store#Limit#Stop Send (mDBOverQuota)#Stop Receive (mDBOverHardQuotaLimit)#Set On#Policy Name" & VbCrLf
While Not objUsersRS.EOF
'# Check if mailbox bypasses Store/Policy limits
Set objUser = GetObject("LDAP://" & objUsersRS.Fields("distinguishedName") & "")
'Get users' homeMDB
strHomeMDB = objUser.homeMDB
Set objHomeMDB = GetObject("LDAP://" & strHomeMDB & "")
strHomeMDBCn = objHomeMDB.distinguishedName
'# Check if User does not have default limits (does not bypass Store/Policy)
If objUser.mDBUseDefaults Then
strUserStatus = strUserLimit & objUser.displayName & "#"
'Check Dictionary for Store
If objStoresDictionary.Exists(strHomeMDBCn) Then
' WScript.Echo "Exists"
strToAdd =strHomeMDBCn & objStoresDictionary.Item(strHomeMDBCn)
' WScript.Echo "strToAdd: " & strToAdd
strUserStatus = strUserStatus & strToAdd
Else
WScript.Echo "Store does not exist in Dictionary"
End If