"invalid JSON primitive" error - Search-UnifiedAuditLog cmdlet

unknown_25 0 Reputation points
2023-06-22T08:22:08.95+00:00

"invalid JSON primitive" error occurred while fetching audits from Sharepoint using Search-UnifiedAuditLog cmdlet in powershell itself. Connect Exchange Online using azure certificate credentials connected successfully but audit fetch results in error for US environments. PowerShell version : 5.1

Screenshot (454)

Anyone help me to resolve this.

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 123.6K Reputation points MVP Volunteer Moderator
    2023-06-22T17:46:35.4166667+00:00

    Works fine here with CBA. Make sure you've assigned sufficient permissions to the service principal, you can assign Exchange-specific roles/role groups now, too.

    If you are in a multi-tenant environment, make sure you're connecting to the correct endpoint. Refer to this article for more details: https://ingogegenwarth.wordpress.com/2023/05/12/the-thing-with-customrouting/


  2. Rich Matheisen 48,026 Reputation points
    2023-06-22T18:35:00.85+00:00

    That error is usually caused by badly formatted Json data. E.g., a trailing comma at the end of the data, a missing square bracket, etc.

    $j = @"
    {
        "Object1": "x"
    },
    {
        "Object2": "y"
    }
    "@
    $x = ConvertFrom-Json -InputObject $j
    
    

    That yields the error:

    ConvertFrom-Json : Invalid JSON primitive: 
    {
        "Object2": "y"
    }.
    

    The error message in the screenshot looks a little odd, too:

    etailsTOPsObject - ConvertFrom-Json $ErrorObject.ErrorDetails.Message

    It looks like there's a minus sign before the ConvertFrom-Json cmdlet.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.