ruudmens / LazyAdmin

SysAdmin scripts for you to use.
MIT License
606 stars 216 forks source link

mfaData array #28

Open brandilton opened 7 months ago

brandilton commented 7 months ago

this is what my mfaData array looked like for some users:

$mfaData = @(
    @{
        "Id" = "28c10230-6103-485e-b985-444c60001490"
        "AdditionalProperties" = @{
            "@odata.type" = "#microsoft.graph.passwordAuthenticationMethod"
            "createdDateTime" = "2022-08-22T20:15:01Z"
        }
    },
    @{
        "Date" = @("Tue, 20 Feb 2024 18:25:46 GMT")
        "OData-Version" = @("4.0")
        "x-ms-ags-diagnostic" = @("{}")
        "Vary" = @("Accept-Encoding")
        "Transfer-Encoding" = @("chunked")
        "client-request-id" = @("d1cb00e6-e362-45ef-8484-f7dfd8ec29de")
        "Strict-Transport-Security" = @("max-age=31536000")
        "request-id" = @("ef51d0d8-e5fb-4831-a44c-6d200cd927cb")
    }
)

on the second pass of the foreach loop it would error with Cannot index into a null array.

I fixed it by filtering down mfaData to just elements that contain AdditionalProperties:

$mfaDataFiltered = $mfaData | Where-Object { $_.AdditionalProperties  }
ForEach ($method in $mfaDataFiltered) {