What is the Office 365 Unified Audit Log?
For security and compliance in Office 365, the Unified Audit Log is probably the most important tool of all. It tracks every user and account action across all of the Office 365 services. You can run reports on deletions, shares, downloads, edits, reads etc, for all users and all products. You can also set up custom alerting to receive notifications whenever specific activities occur.
For all of its usefulness, the most amazing thing about it is that it’s not turned on by default.
It can be frustrating when you come across a query or problem that could easily be resolved if you had access to the logs, only to find out they were never enabled in the first place. Here’s how to get it set up in your own organisation, or if you’re a Microsoft Partner, how to script it for all of your customers using Delegated Administration and PowerShell.
How to enable the Unified Audit Log for a single Office 365 tenant
If you’re only managing your own tenant, it’s quite simple to turn it on. You can do this in two ways.
How to enable the Unified Audit Log via the Security and Compliance Center for a single Office 365 tenant
- Visit https://protection.office.com as an Office 365 admin
- Click Search & investigation
- Click Audit log search
- If it’s not enabled you’ll see a link to Start recording user and admin activities. Click it to enable the Unified Audit Log.
How to enable the Unified Audit Log via PowerShell for a single Office 365 tenant
- Connect to Exchange Online via PowerShell as an administrator by following this guide
- Make sure your Office 365 tenant is ready for the Unified Audit Log by enabling Organization Customization:
Enable-OrganizationCustomization
- Run the following command to enable the Unified Audit Log:
Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true
How to Enable the Unified Audit Log on Multiple Office 365 tenants using Delegated Administration via PowerShell
I’ve recently written a few posts on running bulk PowerShell operations across all of your customer’s Office 365 tenants.
Since the PowerShell command for enabling the Unified Audit Log is just one line, I assumed we’d be able to add it as a script block and run it across all of our Office 365 customers at once.
When I tried setting this up, it initially appeared to be working, though I soon received the following error:
The remote server returned an error: (401) Unauthorized.

It looks like Microsoft don’t allow you to run this particular script using Delegated Administration, though I’m not too sure why. You also can’t enable it via https://protection.office.com using your delegated admin credentials, it just seems to revert you back to the settings for your own Office 365 tenant.
The original version of this article worked around this by creating a temporary Global Administrator with a shared password in every customer tenant. Those scripts don’t meet today’s security standards, so we have retired them (see the security update at the top of this article). The rest of the article is kept for reference, along with the cleanup script for anyone who ran the originals.
This process has three parts
- PowerShell Script One (retired October 2026): Checking Unified Audit Log Status and creating admin users
- PowerShell Script Two (retired October 2026): Enabling Unified Audit Log on all Office 365 tenants and removing successful admins
- PowerShell Script Three (And Optional Script): Removing unsuccessful admins and checking tenants for all unlicensed admins.
Things you should know beforehand
For the most part, these scripts work. Using these three scripts, I’ve enabled the Unified Audit Log on 227 of our 260 delegated Office 365 customers. However, there are a few error messages that can pop up, and a few reasons that will prevent it working for some Office 365 tenants at all.
Here are a few things to keep in mind:
-
It doesn’t work with LITEPACK and LITEPACK_P2 subscriptions
In our case these are Telstra customers running the older Office 365 Small Business and Office 365 Small Business Premium subscriptions. You can run our Office 365 Delegated Tenant license report to identify these customers.

-
It does not work on customers that don’t have any subscriptions, or only has expired subscriptions.
It won’t work for Office 365 tenants that don’t have any Office 365 subscriptions, or if their Office 365 subscriptions have expired. The script will fail for these organisations with the error: The tenant organization isn’t in an Active State. Complete the administrative tasks that are active for this organization, and then try again.

-
It does not work on customers that only have Dynamics CRM licences
This script doesn’t seem to run on customers that only have Dynamics CRM Online. It hasn’t been tested with customers that only have Dynamics 365.
PowerShell Script One: Checking Unified Audit Log Status and creating admin users
This script uses your own delegated admin credentials. It creates a list of all of your Office 365 Customers and reports on their subscriptions. If they have at least one subscription (active or not) it attempts to run an Exchange Online cmdlet to check whether the Unified Audit Log is enabled. If it’s enabled, it does nothing and moves onto the next customer. If it’s disabled, it creates a new user, assigns it to the Company Administrator role and adds a row to a CSV with the tenant ID, customer name and user principal name.

Retired October 2026: This script checked whether the unified audit log was turned on in each customer tenant and, where it was off, created a temporary Global Administrator account with the same default password (Password123 unless you changed it) in each one. It signed in to Microsoft 365 with a password-only partner account. We no longer recommend shared admin accounts, because anyone who knows the password has full control of the customer’s tenant. Today, have a named technician with a suitable GDAP role, who signs in with MFA, turn auditing on for each customer by following Microsoft’s Turn auditing on or off steps (linked in the notice at the top of this article).
See the Unified Audit Log status for your customers
One of the outputs of this script is the UALCustomerStatus.csv file. You can make a copy of this, and rerun the process at the end to compare the results.

Browse the list of created admins
The script will also create a CSV containing the details for each admin created. This CSV will be imported by the second PowerShell Script and will be used to enable the Unified Audit Log on each tenant.

PowerShell Script Two: Enabling Unified Audit Log on all Office 365 tenants and removing successful admins
Retired October 2026: This script signed in to each customer tenant as the temporary Global Administrator, using the shared password over basic authentication, and kept the account in place whenever enabling the audit log failed. If you ran it, check every customer for leftover admin accounts that use the prefix you chose (the default was gcitsauditadmin) and delete them, rather than recreating or reusing them. Today, turn auditing on through a GDAP role assigned to a named technician who signs in with MFA.
View the successful Office 365 admins that were removed
If the Unified Audit Log was enabled successfully, the newly created Office 365 admin will be automatically removed. You can see the results of this in the RemovedAdmins CSV.

See the remaining Office 365 admins that couldn’t enable the Unified Audit Log
If the Unified Audit Log couldn’t be enabled, the Office 365 admin will remain unchanged.
PowerShell Script Three: Removing unsuccessful admins
Any tenants that weren’t able to have their Unified Audit Log enabled via PowerShell will still have the Office 365 admin active. This script will import these admins from the RemainingAdminsCsv and remove them.
Once removed, it will add them to the RemovedAdmins CSV. You can compare this to the CreatedAdmins CSV from the first script to make sure they’re all gone.
<# This script removes the temporary admin users that the original first script created and that are still listed in the RemainingAdmins CSV. #>
#-------------------------------------------------------------
# Here are some things you can modify:
# This is your partner admin user name that has delegated administration permission
$UserName = "admin@contoso.onmicrosoft.com"
# This CSV contains a list of all remaining unsuccessful admins left unchanged by the second script.
$RemainingAdmins = import-csv "C:\temp\RemainingAdmins.csv"
# This CSV will contain a list of all admins removed by this script.
$RemovedAdminsCsv = "C:\temp\RemovedAdmins.csv"
#-------------------------------------------------------------
$Cred = get-credential -Credential $UserName
Connect-MsolService -Credential $cred
ForEach ($Admin in $RemainingAdmins) {
$tenantID = $Admin.Tenantid
$upn = $Admin.UserPrincipalName
Write-Output "Deleting user: $upn"
Remove-MsolUser -UserPrincipalName $upn -TenantId $tenantID -Force
$AdminProperties = @{
TenantId = $tenantID
CompanyName = $Admin.CompanyName
DefaultDomainName = $Admin.DefaultDomainName
UserPrincipalName = $upn
Action = "REMOVED"
}
$RemovedAdmins = @()
$RemovedAdmins += New-Object psobject -Property $AdminProperties
$RemovedAdmins | Select-Object TenantId,CompanyName,DefaultDomainName,UserPrincipalName,Action | Export-Csv -notypeinformation -Path $RemovedAdminsCsv -Append
}
Want to see all the current Office 365 global administrators in your customers tenants?
To confirm that all of the created admins from these scripts have been removed, or just to see which global administrators have access to your customer tenants, you can run the scripts here. If required, there’s a second script that will block the credentials of the admins that you leave in the exported CSV.


