IBM Support

Get-ComplianceSearch Powershell Error in M365 for Mailbox Searches

How To


Summary

The error indicates that the `Get-ComplianceSearch` cmdlet is not available in your current PowerShell session. This cmdlet is part of the Microsoft Purview compliance tools in Microsoft 365 and is used for managing eDiscovery searches in Exchange Online. It's not a built-in Windows PowerShell cmdlet, so it requires connecting to the appropriate Microsoft 365 service and having the necessary permissions.

Objective

The term 'Get-complianceSearch' is not recognized as the name of a cmdlet in native PowerShell, 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.

 

Common Causes

- Missing Module Connection: You haven't imported the Security & Compliance Center cmdlets into your session.

- Insufficient Permissions: Your account lacks roles like eDiscovery Manager or Compliance Administrator, which are required to access these cmdlets.

- Outdated or Incorrect Connection Method: Older methods (e.g., using `New-PSSession` for Exchange Online) don't expose compliance cmdlets; you need the modern unified approach.

- PowerShell Environment: Ensure you're using PowerShell 5.1 or later (or PowerShell 7+ for cross-platform support).

 

Environment

M365

Steps

 Step-by-Step Solution

1. Install Required Modules (if not already installed):

  - Open PowerShell as an Administrator.

  - Run the following to install the Microsoft Graph modules (recommended for modern authentication; the legacy Security & Compliance module is deprecated but still works for now):

     ```

     Install-Module Microsoft.Graph -Scope CurrentUser -Force

     Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force

     ```

  - If you prefer the legacy method (less secure, but simpler for some), install:

     ```

     Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force

     ```

 

2. Connect to Microsoft 365 Services:

   - For the modern Microsoft Graph approach (preferred for long-term use):

     ```

     Connect-MgGraph -Scopes "Compliance.ReadWrite", "eDiscovery.ReadWrite.All"

     Connect-ExchangeOnline -UserPrincipalName youradmin@yourdomain.com

     ```

     - This prompts for authentication (supports MFA). Replace `youradmin@yourdomain.com` with your admin email.

     - The scopes ensure access to compliance features.

   - For the legacy Security & Compliance Center approach (if Graph doesn't work for your setup):

     ```

     Connect-IPPSSession -UserPrincipalName youradmin@yourdomain.com

     ```

     - This directly imports the compliance cmdlets (e.g., `Get-ComplianceSearch`).

 

3. Verify the Cmdlet is Available:

   - After connecting, run:

     ```

     Get-Command Get-ComplianceSearch

     ```

  - If it returns details about the cmdlet, it's loaded. If not, disconnect (`Disconnect-ExchangeOnline` or `Disconnect-MgGraph`) and retry the connection.

 

4. Assign Required Permissions (if the cmdlet loads but commands fail):

  - Log in to the Microsoft Purview compliance portal.

  - Go to Permissions > Microsoft Purview solutions > Roles.

  - Add your account to the eDiscovery Manager role group (or Compliance Administrator for broader access).

  - It may take 15-60 minutes for permissions to propagate. Sign out and reconnect to PowerShell afterward.

  - Alternatively, use the Microsoft 365 admin center under Users > Active users > Select your user > Roles to assign roles like Organization Management or Discovery Management.

 

5. Run Your Original Command:

   - Once connected and permissions are set, your command should work:

     ```

     Get-ComplianceSearch | Where-Object { $_.SourceMailboxes -contains "91..." }

     ```

  - If the search doesn't return results, verify the compliance search exists via `Get-ComplianceSearch` without filters.

Additional Information

Additional Tips

- Restart PowerShell: Close and reopen your PowerShell window after connections or module installs to clear any session issues.

- Check Connection Status: Run `Get-ConnectionInformation` (after `Connect-ExchangeOnline`) to confirm you're authenticated.

- Legacy vs. Modern: If you're on an older setup, the `Connect-IPPSSession` might be quicker, but Microsoft recommends migrating to Microsoft Graph for better security and features.

 

- Troubleshooting Further Errors:

 - If you get authentication errors, ensure MFA is enabled and you're using a global admin or appropriately licensed account (E3/E5 or equivalent).

 - For on-premises Exchange (not Online), these cmdlets aren't available—use the Exchange Management Shell instead.

 - Test with a simple command first: `Get-ComplianceSearch` (lists all searches).

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB66","label":"Technology Lifecycle Services"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SSWBPX","label":"Microsoft M365 Platform"},"ARM Category":[{"code":"a8mKe000000004GIAQ","label":"M365 Platform"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":""}]

Document Information

Modified date:
25 November 2025

UID

ibm17252551