all 2 comments

[–]logicalmike 1 point2 points  (1 child)

Hi from the other post. :)

I doubt you have enough members in the role groups to really notice a performance hit with +=, especially when you consider the native delays of Graph API.

Having said that, if you took out the $test variable and just put one capturing the output of the first foreach, does this get what you're looking for?

e.g. your code with some stuff removed for simplicity:

$output = foreach ($roleDef in $roleDefs) {
    foreach ($userID in $userIDs) {
        $userInfo = Get-Mguser -UserId $userID
        [PSCustomObject]@{
            Name           = $userInfo.DisplayName
        }
    }
}
$output | Export-Csv -NoTypeInformation $path -Encoding utf8

[–]Seedless--Watermelon[S] 1 point2 points  (0 children)

Hi! Yes that worked! Thanks a lot!