Forum Discussion

dmarquesgn's avatar
dmarquesgn
Iron Contributor
Dec 13, 2022
Solved

Use Powershell to get data from Defender Advanced Hunting Queries

Hi,

I have an advanced query on Defender to extract the number of vulnerabilities by it's severity type, which is this one:

DeviceTvmSoftwareVulnerabilities
    | summarize count() by  VulnerabilitySeverityLevel
    | order by VulnerabilitySeverityLevel

Basically this produces a very simple table with this data:

Critical - 1000
High - 1000

Medium - 1000

Low - 1000

 

Is there any way to get this query from Powershell, so then I can some extra tasks after?

 

Thanks

  • 403 is usually permissions - check the token as it's either expired or doesn't contain all relevant scopes.

8 Replies

    • dmarquesgn's avatar
      dmarquesgn
      Iron Contributor

      VasilMichev 

      I'm having some issues on my tries to use the Microsoft Graph API query directly, which was my first attempt. So usually I call the request like this:

      $vulnResponse = Invoke-WebRequest -Method Get -Uri $vulnUrl -Headers $headers -ErrorAction Stop

      So, according to the documentation I have to build out a query like this:

      https://graph.microsoft.com/beta/security/runHuntingQuery { "query": "DeviceTvmSoftwareVulnerabilities | summarize count() by  VulnerabilitySeverityLevel" }"

      But when I run the web request I get a 401 (Unauthorized), which is strange, because on the permissions side I got the Ti.Read.All allowed, and also, if I run a query to the Microsoft Defender API (https://api-eu.securitycenter.windows.com/api/vulnerabilities/machinesVulnerabilities?) I can run it without any permission issues.

      This is what I have configured on the API permissions:

      What am I missing here?

      Thanks

      • VasilMichev's avatar
        VasilMichev
        MVP
        This is a Graph method, so you need to add the corresponding Graph permissions (ThreatHunting.Read.All) - you cannot just rely on exiting permissions for a different API.

Resources