I think i've managed to create what I'm after now. It seems to be working well for me (added a parameter for the permission type)
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")
# Reference Custom report collumns
$column_mailbox = "{b4ee813c-2ae8-4a62-9fc8-2a0cf1bf909b}" #Collumn ID of Mailbox custom objectID collumn
$column_permission = "{d5ae6fbf-3ce6-4ab1-8ada-dce2c64fa8a4}" #Collumn ID of Mailbox custom objectID collumn
{d5ae6fbf-3ce6-4ab1-8ada-dce2c64fa8a4}
# Split out multiple mailboxes
$mailboxes = "%param-Mailbox%"
$mailboxes = $mailboxes.split(";")
Foreach ($mailbox in $mailboxes) {
# Create hash table and specify column value
$columnValues = @{ }
$columnValues.Add($column_mailbox, "$mailbox")
$columnValues.Add($column_permission, "%param-permission%")
# Bind to the mailbox
$user = $admService.OpenObject("Adaxes://$mailbox", $NULL, $NULL, 0)
# Get Exchange properties
$mailboxParams = $user.GetMailParameters()
If ("%param-permission%" -eq "Full Access"){
$fullAccess = $mailboxParams.MailboxRights.GetTrusteesGrantedRights("ADM_EXCHANGE_MAILBOX_RIGHTS_FULL_ACCESS")
if ($fullAccess.Length -eq 0) {$Context.LogMessage("No 'Full Access' rights on mailbox", "Information")}
Else {
foreach ($object in $fullAccess) {
If ($object.DisplayName -ne "self"){
# Add item to report
$userDN = $object.SearchResult.AdsPath.DN
$item = $Context.BindToObjectByDN("$userDN")
$Context.Items.Add($item, $columnValues)
}
}
}
}
ElseIf ("%param-permission%" -eq "Send As"){
$sendAs = $mailboxParams.SendAs
if ($sendAs.Length -eq 0) {$Context.LogMessage("No 'Send as' rights on mailbox", "Information")}
Else {
foreach ($object in $sendAs) {
If ($object.DisplayName -ne "self"){
# Add item to report
$userDN = $object.SearchResult.AdsPath.DN
$item = $Context.BindToObjectByDN("$userDN")
$Context.Items.Add($item, $columnValues)
}
}
}
}
Else {
$sendOnBehalfOf = $mailboxParams.GrantSendOnBehalfTo
if ($sendOnBehalfOf.Length -eq 0) {$Context.LogMessage("No 'Send On Behalf Of' rights on mailbox", "Information")}
Else {
foreach ($object in $sendOnBehalfOf) {
If ($object.DisplayName -ne "self"){
# Add item to report
$userDN = $object.SearchResult.AdsPath.DN
$item = $Context.BindToObjectByDN("$userDN")
$Context.Items.Add($item, $columnValues)
}
}
}
}
}
Also created one for running on an OU/Domain too (might take a while)
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")
# Search filter
$filterUsers = "(sAMAccountType=805306368)"
$Context.DirectorySearcher.AppendFilter($filterUsers)
# Reference Custom report collumns
$column_mailbox = "{b4ee813c-2ae8-4a62-9fc8-2a0cf1bf909b}" #Collumn ID of Mailbox custom objectID collumn
$column_permission = "{d5ae6fbf-3ce6-4ab1-8ada-dce2c64fa8a4}" #Collumn ID of Mailbox custom objectID collumn
# Add properties necessary to generate the report
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add("distinguishedname")
# Generate report
try
{
$searchIterator = $Context.DirectorySearcher.ExecuteSearch()
while ($Context.MoveNext($searchIterator))
{
$searchResult = $searchIterator.Current
$MailboxDN = $searchResult.GetPropertyByName("distinguishedname").Values[0]
# Bind to the mailbox
$user = $admService.OpenObject("Adaxes://$mailboxDN", $NULL, $NULL, 0)
# Get Exchange properties
$mailboxParams = $user.GetMailParameters()
$columnValues = @{
$column_mailbox = $MailboxDN;
$column_permission = "%param-permission%";}
#$Context.Items.Add($searchResult, $columnValues, $NULL)
If ("%param-permission%" -eq "Full Access"){
$fullAccess = $mailboxParams.MailboxRights.GetTrusteesGrantedRights("ADM_EXCHANGE_MAILBOX_RIGHTS_FULL_ACCESS")
if ($fullAccess.Length -eq 0) {$Context.LogMessage("No 'Full Access' rights on mailbox", "Information")}
Else {
foreach ($object in $fullAccess) {
If ($object.DisplayName -ne "self"){
# Add item to report
$userDN = $object.SearchResult.AdsPath.DN
$item = $Context.BindToObjectByDN("$userDN")
$Context.Items.Add($item, $columnValues)
}
}
}
}
ElseIf ("%param-permission%" -eq "Send As"){
$sendAs = $mailboxParams.SendAs
if ($sendAs.Length -eq 0) {$Context.LogMessage("No 'Send as' rights on mailbox", "Information")}
Else {
foreach ($object in $sendAs) {
If ($object.DisplayName -ne "self"){
# Add item to report
$userDN = $object.SearchResult.AdsPath.DN
$item = $Context.BindToObjectByDN("$userDN")
$Context.Items.Add($item, $columnValues)
}
}
}
}
Else {
$sendOnBehalfOf = $mailboxParams.GrantSendOnBehalfTo
if ($sendOnBehalfOf.Length -eq 0) {$Context.LogMessage("No 'Send On Behalf Of' rights on mailbox", "Information")}
Else {
foreach ($object in $sendOnBehalfOf) {
If ($object.DisplayName -ne "self"){
# Add item to report
$userDN = $object.SearchResult.AdsPath.DN
$item = $Context.BindToObjectByDN("$userDN")
$Context.Items.Add($item, $columnValues)
}
}
}
}
}
}
finally
{
if ($searchIterator) { $searchIterator.Dispose() }
}