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
857 stars 308 forks source link

Handling null value quotaId #255

Closed mthreer closed 2 months ago

mthreer commented 2 months ago

In a recent deployment of AzGovWiz we discovered that the setup wouldn't carry on when it stumbled upon a subscription with a null-valued .quotaId.

After extensive debugging, we discovered a way forward by excluding a subscription we believed to be causing troubles. This erroneous subscription was first excluded in an ugly way, by its subscription name "Free Trial". But, the real reason it failed was due to the .quotaId being null. There wasn't much detail provided in the output regarding this, it simply stopped at "Subscription picking" with the error "You cannot call a method on a null-valued expression."

However, the error comes from the .startsWith() method that is validating if the property value .quotaId starts with AAD_, but against a null-valued .quotaId.

Example: $null.startsWith('xyz')

Will give you the output of: InvalidOperation: You cannot call a method on a null-valued expression.

This PR simply evaluates if .quotaId is null first, and then puts these subscriptions with the null-valued .quotaId out of scope.

JulianHayward commented 2 months ago

@mthreer thank you! But please stick to the contribution guide

mthreer commented 2 months ago

@JulianHayward Sorry, I missed that! I will redo :)