Hello,
Yes, you can read and modify Exchange-specific properties of AD objects directly in Active Directory, just the same as you do with any other properties of AD objects. However, we recommend resorting to the Exchange ADSI API anywhere possible, because it is the method recommended by Microsoft. We can't guarantee that simply modifying a property will work in all cases on the Exchange side.
Anyway, here's a script that emails an HTML-formatted report on all users who have the ms-Exch-MDB-Over-Hard-Quota-Limit set, and then removes the limit without using Adaxes Exchange ADSI API:
# E-mail settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Users Who have Hard Mailbox Quotas Specified" # TODO: modify me
$reportHeader = "<h2><b>Users Who have Hard Mailbox Quotas (<i>ms-Exch-MDB-Over-Hard-Quota-Limit</i>) Specified</b></h2>" # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
# Search users who have the 'ms-Exch-MDB-Over-Hard-Quota-Limit' attribute set
$searcher = $Context.BindToObject("Adaxes://rootDSE")
$searcher.SearchFilter = "(&(sAMAccountType=805306368)(!(name=DiscoverySearchMailbox*))(!(userAccountControl:1.2.840.113556.1.4.803:=2))(mDBOverHardQuotaLimit=*))"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500
$searcher.VirtualRoot = $True
try
{
$searchResultIterator = $searcher.ExecuteSearch()
$users = $searchResultIterator.FetchAll()
# Get the default Web Interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
$Context.LogMessage("Default web interface address not set for Adaxes service. For details, see http://www.adaxes.com/help/?HowDoI.ManageService.RegisterWebInterface.html", "Warning")
}
$reportHeader += "<ol>"
foreach ($userID in $users)
{
# Bind to the user
$user = $Context.BindToObject($userID.AdsPath)
# Add user info to the report
$guid = [Guid]$user.Get("objectGuid")
$userDisplayName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($userID.AdsPath, "IncludeParentPath")
$reportHeader += "<li><a href='$webInterfaceAddress`ViewObject.aspx?guid=$guid'>$userDisplayName</a></li>"
# Clear the 'ms-Exch-MDB-Over-Hard-Quota-Limit' attribute
$user.Put("mDBOverHardQuotaLimit", $NULL)
$user.SetInfo()
}
$reportHeader += "</ol>"
$reportHeader += "Users found:" + $users.Length
$htmlReport = $reportHeader + $reportFooter
# Send mail
$Context.SendMail($to, $subject, $NULL, $htmlReport)
}
finally
{
$searchResultIterator.Dispose()
}
Here's a version of the script that does the same using Adaxes Exchange ADSI API:
# E-mail settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Users Who have Hard Mailbox Quotas Specified" # TODO: modify me
$reportHeader = "<h2><b>Users Who have Hard Mailbox Quotas (<i>ms-Exch-MDB-Over-Hard-Quota-Limit</i>) Specified</b></h2>" # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
# Search users who have the 'ms-Exch-MDB-Over-Hard-Quota-Limit' attribute
$searcher = $Context.BindToObject("Adaxes://rootDSE")
$searcher.SearchFilter = "(&(sAMAccountType=805306368)(!(name=DiscoverySearchMailbox*))(!(userAccountControl:1.2.840.113556.1.4.803:=2))(mDBOverHardQuotaLimit=*))"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500
$searcher.VirtualRoot = $True
try
{
$searchResultIterator = $searcher.ExecuteSearch()
$users = $searchResultIterator.FetchAll()
# Get the default Web Interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
{
$Context.LogMessage("Default web interface address not set for Adaxes service. For details, see http://www.adaxes.com/help/?HowDoI.ManageService.RegisterWebInterface.html", "Warning")
}
# Create an instance of the AdmExchangeMailboxParameters class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Remove Prohibit Send and Receive Quota
$storageQuotas = $mailboxParams.StorageQuotas
$storageQuotas.IsModificationEnabled = $True
$storageQuotas.ProhibitSendReceiveQuotaModificationEnabled = $True
$reportHeader += "<ol>"
foreach ($userID in $users)
{
# Bind to the user
$user = $Context.BindToObject($userID.AdsPath)
# Add user info to the report
$guid = [Guid]$user.Get("objectGuid")
$userDisplayName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($userID.AdsPath, "IncludeParentPath")
$reportHeader += "<li><a href='$webInterfaceAddress`ViewObject.aspx?guid=$guid'>$userDisplayName</a></li>"
# Disable Prohibit Send and Receive Quota
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
}
$reportHeader += "</ol>"
$reportHeader += "Users found:" + $users.Length
$htmlReport = $reportHeader + $reportFooter
# Send mail
$Context.SendMail($to, $subject, $NULL, $htmlReport)
}
finally
{
$searchResultIterator.Dispose()
}
In the scripts, modify the following to meet your requirements:
- $to - specifies the recipient of the report;
- $subject - specifies the e-mail message subject;
- $reportHeader - specifies the report header;
- $reportFooter - specifies the report footer.
To schedule the report, create a Scheduled Task configured for the Domain-DNS object type.