Microsoft 365 – Exchange Online : resolving error – Search-UnifiedAuditLog : The term ‘Search-UnifiedAuditLog’ is not recognized as the name of a cmdlet, function, script file, or operable program – permission issue

Microsoft 365 - Exchange Online - error while executing the PowerShell CMDLET - "Search-UnifiedAuditLog" - The term 'Search-UnifiedAuditLog' is not recognized as the name of a cmdlet, function, script file, or operable program
Microsoft 365 - Exchange Online - error while executing the PowerShell CMDLET - "Search-UnifiedAuditLog" - The term 'Search-UnifiedAuditLog' is not recognized as the name of a cmdlet, function, script file, or operable program

Hi All,

Greetings for the day !!!

Today new issue and solution !!!

Details / Background

  • We are writing PowerShell script to fetch the audit logs
  • We are using “Search-UnifiedAuditLog” CMDLET for fetching the respective audit logs based on parameters

Search-UnifiedAuditLog
      -EndDate <ExDateTime>
      -StartDate <ExDateTime>
      [-Formatted]
      [-FreeText <String>]
      [-IPAddresses <String[]>]
      [-ObjectIds <String[]>]
      [-Operations <String[]>]
      [-RecordType <AuditRecordType>]
      [-ResultSize <Int32>]
      [-SessionCommand <UnifiedAuditSessionCommand>]
      [-SessionId <String>]
      [-SiteIds <String[]>]
      [-UserIds <String[]>]
      [<CommonParameters>]

  • We have latest version of “ExchangeOnlineManagement” module is installed
  • In PowerShell script we could successfully import “ExchangeOnlineManagement
  • We could successfully connect with Exchange Online using CMDLET – Connect-ExchangeOnline with the account which we are using
  • But still we have an error

Issue / Error

Microsoft 365 - Exchange Online - error while executing the PowerShell CMDLET - "Search-UnifiedAuditLog" - The term 'Search-UnifiedAuditLog' is not recognized as the name of a cmdlet, function, script file, or operable program
fig : Microsoft 365 – Exchange Online – error while executing the PowerShell CMDLET – “Search-UnifiedAuditLog” – The term ‘Search-UnifiedAuditLog’ is not recognized as the name of a cmdlet, function, script file, or operable program

Search-UnifiedAuditLog : The term ‘Search-UnifiedAuditLog’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1

  • Search-UnifiedAuditLog
  • ~~~~~~
    • CategoryInfo : ObjectNotFound: (Search-UnifiedAuditLog:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

Solution / Cause of an error

  • As mentioned above as well we have latest version of “ExchangeOnlineManagement” module is installed and we could successfully import “ExchangeOnlineManagement
  • Then this was the permission issue – account which we are using to execute the cmdlet – “Search-UnifiedAuditLog” don’t have permissions
  • With the help of Global Admin account we can find the permissions required to execute this CMDLET using Get-ManagementRole as

PS C:\> Get-ManagementRole -Cmdlet Search-UnifiedAuditLog

Name                 RoleType         
----                 --------         
Audit Logs           AuditLogs        
View-Only Audit Logs ViewOnlyAuditLogs



PS C:\> 

Microsoft 365 - Exchange Online - Verifying the permission to view the required permission to execute CMDLET - Search-UnifiedAuditLog
fig : Microsoft 365 – Exchange Online – Verifying the permission to view the required permission to execute CMDLET – Search-UnifiedAuditLog
  • This means to fetch the audit logs (executing – “Search-UnifiedAuditLog“) our user should be part of group which has role assigned either “Audit Logs” OR “View-Only Audit Logs
  • To grant the user required permissions, we need to add user into a role group which contains “Audit Logs” or “View-Only Audit Logs” such as “View-Only Organization Management
  • We could add user to respective role group either by using PowerShell or Exchange Online admin center

Add user to respective Exchange role group using PowerShell

Add-RoleGroupMember <Role Group Name> -Member <User>

Add-RoleGroupMember "View-Only Organization Management" -Member "prasham@knowledgejunction1.onmicrosoft.com"

Add user to respective Exchange role group from Exchange online admin center

Microsoft 365 - Exchange Online - Exchange admin center
fig : Microsoft 365 – Exchange Online – Exchange admin center
  • From left blade, navigate to Roles >> Admin roles
Microsoft 365 - Exchange Online - Admin roles - Role group - View-Only Organization Management
fig : Microsoft 365 – Exchange Online – Admin roles – Role group – View-Only Organization Management
  • Find the Role Group in which we need to add user
  • As shown in below fig, in middle tab “Assigned“, click on “+Add” link to add the user
Microsoft 365 - Exchange Online - Admin roles - Role group - View-Only Organization Management - Add Member
fig : Microsoft 365 – Exchange Online – Admin roles – Role group – View-Only Organization Management – Add Member
  • Search the user which we need to add
fig : Microsoft 365 - Exchange Online - Admin roles - Role group - View-Only Organization Management - Add Member
fig : Microsoft 365 – Exchange Online – Admin roles – Role group – View-Only Organization Management – Add Member
  • Once user have respective permissions, he/she will be able to successfully execute the command
Microsoft 365 - Exchange Online - Executing CMDLET -  "Search-UnifiedAuditLog"
fig : Microsoft 365 – Exchange Online – Executing CMDLET – “Search-UnifiedAuditLog

Thanks for reading!!! Please feel free to discuss in case any questions / suggestions / thoughts !!!

HAVE A GREAT TIME AHEAD !!! LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading