JulianHayward / Azure-MG-Sub-Governance-Reporting

Azure Governance Visualizer aka AzGovViz is a PowerShell script that captures Azure Governance related information such as Azure Policy, RBAC (a lot more) by polling Azure ARM, Storage and Microsoft Graph APIs.
MIT License
817 stars 295 forks source link

SecureScore fails when more than one value is returned by api #176

Closed HeikoNeblung closed 1 year ago

HeikoNeblung commented 1 year ago

v6_major_20230323_1 please only report bug if you are running the latest version of AzGovViz

Console e.g. Console, Azure DevOps, GitHub Action, Cloud Shell, GitHub CodeSpaces ..

Describe the bug

The Script Fails when running command

./pwsh/AzGovVizParallel.ps1 -ManagementGroupId <ManagementGroupId>

the following Error is thrown

5/7 Subscriptions processed
InvalidOperation:
Line |
  16 |  …             $secureScorePercentageRounded = [math]::Round(($subASCSec …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.

This happens when one of the suscriptions in current scope returns more than one value for a call to secureScores API (function dataCollectionASCSecureScoreSub)

Additional context The scureScores API for the subscription mentioned above will return something like

{
  "value": [
    {
      "id": "/subscriptions/****/providers/Microsoft.Security/secureScores/ascScore",
      "name": "ascScore",
      "properties": {
        "displayName": "ASC score",
        "score": {
          "current": 38.58,
          "max": 56,
          "percentage": 0.6889
        },
        "weight": 1413
      },
      "type": "Microsoft.Security/secureScores"
    },
    {
      "id": "/subscriptions/****/providers/Microsoft.Security/secureScores/scoreGraceExcluded",
      "name": "scoreGraceExcluded",
      "properties": {
        "displayName": "Score grace excluded",
        "score": {
          "current": 19.52,
          "max": 48,
          "percentage": 0.4067
        },
        "weight": 2122
      },
      "type": "Microsoft.Security/secureScores"
    }
  ]
}
JulianHayward commented 1 year ago

@HeikoNeblung thanks for reporting and details. So let´s filter .where({ $_.name -eq 'ascScore' }) ?

Will you create a PR?

HeikoNeblung commented 1 year ago

Yes, I will prepare a PR

JulianHayward commented 1 year ago

fixed with v6_major_20230325_1