How to retrieve the value of @odata.count

Ravindra Shukla 26 Reputation points
2021-05-10T15:03:31.417+00:00

Hi,

I am writing a powershell script to retrieve the count of unread emails of an user using Microsoft Graph API.
However its returning me a full response as below, however I only want to retrieve the value 281 of "@odata.count" field in the response and display as output of my powershell script.

Could you please help me with this query? How can I achieve this or whether this is possible and if yes, how to use this in powershell script?

Thank you.

> {
> "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('677887655689900098888')/messages",
> "@odata.count": 281,
> "value": [
> {
> "@odata.etag": "WAAAA\AACCCNNJHHHHFHHJF"",
> "id": "WAAAA\AACCCNNJHHHHFHHJWAAAA\AACCCNNJHHHHFHHJFWAAAA\AACCCNNJHHHHFHHJFWAAAA\AACCCNNJHHHHFHHJF=",
> "createdDateTime": "2021-05-03T14:19:22Z",
> "lastModifiedDateTime": "2021-05-03T14:19:24Z",
> "changeKey": "CQAAABYAAAAiIsqMbYjsT5e/T7KzowPTAAOIXIRc",
> "categories": [],
> "receivedDateTime": "2021-05-03T14:19:23Z",
> "sentDateTime": "2021-05-03T14:19:23Z",
> "hasAttachments": false,

Microsoft Security | Microsoft Graph
0 comments No comments

3 answers

Sort by: Oldest
  1. Vasil Michev 128.7K Reputation points MVP Volunteer Moderator
    2021-05-10T17:11:41.05+00:00

    The full code would be helpful, but assuming you are storing the response in $resp variable, it will be something like:

    ($resp.Content | ConvertFrom-Json).'@odata.count'
    

    Was this answer helpful?

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  3. Ravindra Shukla 26 Reputation points
    2021-05-12T06:21:39.573+00:00

    Hi @Vasil Michev ,

    Its working now. Thank you for your help.

    Was this answer helpful?

    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.