0 votes

I need a Scheduled Task that send an email of a list of all users that have an on prem mailbox. I have found the script to check if the mailbox is on prem but have not found the way to build and email the list. It can be in CSV fomat.

by (1.3k points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

Have a look at the following script from our repository: https://www.adaxes.com/script-repositor ... s-s418.htm.

0

Looks like the script would build a report of all users with exchange mailboxes. How would I change it to only report on specific office locations and for people with on-prem mailboxes?

e.g. If Office = Orlando or Tampa or Miami & the mail is On-Prem add to list

0

Hello,

Try the updated script below. In the script, the $offices variable specifies the list of possible values for the Office property of the users with on-premise Exchange mailboxes to be included into the report.

$csvFilePath = "C:\Scripts\Report.csv" # TODO: modify me
$offices = @("Orlando", "Tampa", "Miami") # TODO: modify me
$removeCsvFile = $True # TODO: modify me
$propertiesToExport = @("givenName", "middleName", "sn", "title", "co", "mail") # TODO: modify me

# Email message settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Active Users with on-premise Exchange Mailboxes" # TODO: modify me
$from = "noreply@domain.com" # TODO: Modify me
$mailServer = "mail.domain.com" # TODO: Modify me
$body = "Active Users with on-premise Exchange Mailboxes" # TODO: Modify me

function SearchObjects($filter, $propertiesToLoad)
{
    # Set search parameters
    $searcher = $Context.BindToObject("Adaxes://rootDSE")
    $searcher.SearchFilter = $filter
    $searcher.SearchScope = "ADS_SCOPE_SUBTREE"
    $searcher.PageSize = 500
    $searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
    $searcher.SetPropertiesToLoad($propertiesToLoad)
    $searcher.VirtualRoot = $True

    try
    {
        # Perform the search
        $searchResultIterator = $searcher.ExecuteSearch()
        $searchResults = $searchResultIterator.FetchAll()

        return ,$searchResults
    }
    finally
    {
        # Release resources
        if ($searchResultIterator){ $searchResultIterator.Dispose() }
    }
}

# Build filter
$dateFileTime = [System.DateTime]::UtcNow.ToFileTimeUTC()
$filter = New-Object "System.Text.StringBuilder"
[void]$filter.Append("(&(sAMAccountType=805306368)(|(accountExpires=>$dateFileTime)(accountExpires=0)(accountExpires=9223372036854775807))(!(userAccountControl:1.2.840.113556.1.4.803:=2))(mailNickname=*)(msExchHomeServerName=*)")
[void]$filter.Append("(msExchRecipientTypeDetails=1)")
[void]$filter.Append("(|")
foreach ($office in $offices)
{
    [void]$filter.Append("(physicalDeliveryOfficeName=$office)")
}
[void]$filter.Append("))")

# Find all active users with on-premise mailboxes in certain offices
$searchResults = SearchObjects $filter.ToString() $propertiesToExport

if ($searchResults.Length -eq 0)
{
    $Context.LogMessage("No active users with Exchange mailboxes found", "Information")
    return
}

$records = @($NULL) * $searchResults.Length
for ($i = 0; $i -lt $searchResults.Length; $i++)
{
    $record = @{}
    foreach ($property in $propertiesToExport)
    {
        $record.Add($property, $searchResults[$i].Properties[$property].Value)
    }
    $records[$i] = New-Object PSObject -Property $record
}
$records | Export-Csv -Path $csvFilePath -NoTypeInformation

# Send mail
Send-MailMessage -to $to -From $from -Subject $subject -Body $body -SmtpServer $mailServer -Attachments $csvFilePath

if ($removeCsvFile)
{
    # Remove CSV File
    Remove-Item $csvFilePath -Force
}
0

If I wanted to exclude a list of job titles from this report how would I update the script?

Exclude a job title.

Related questions

0 votes
1 answer

Hello, We are using adaxes with a M365 hybrid environment and right now we have to manually create a remote mailbox on prem after user creation. ... -Identity "user@mydomain.com" -ExternalEmailAddress "user@mydomain.onmicrosoft.com" Enable-RemoteMailbox "user"

asked Oct 16, 2020 by copatterson (70 points)
0 votes
1 answer

Hello, I have a sheduled task running. This task checks if a user is a member of a Licensed Office 365 Group with exchange online. If the user does not have an ... the on prem exchange mailbox and the exchange online mailbox? Thanks if you have an idea!

asked Feb 24, 2023 by fabian.p (320 points)
0 votes
1 answer

Topic question, we are looking into AD Auditing and I would like to know if this solution is on-prem. And I would like to know if there is a built in report to see ... to access folders they do not have permissions to, is this something I can do with Adaxes?

asked Jun 10, 2021 by anthonysmills (20 points)
0 votes
1 answer

Hi after the user acount is created in Active Directory I need the business rule to pause for 30mins for the azure sync to take place before the rule can continue to add the 365 license.

asked May 24 by johanpr (120 points)
0 votes
1 answer

I've got the following script so far using the SDK but running into an error: You cannot call a method on a null-valued expression. At line:1 char:1 + ... .BindToObjectByDN("$object.SearchResult.AdsPath.DN") $Context.Items.Add($item, $columnValues) } } } }

asked May 19, 2021 by richarddewis (260 points)
3,411 questions
3,108 answers
7,912 comments
545,838 users