The easy way to download all role assignment in a directory is already available
Sign in to the Azure portal or Azure AD admin center. Select Azure Active Directory > Roles and administrators, select All roles, Select Download assignments.
A CSV file that lists assignments at all scopes for all roles is downloaded.
----------
--please don't forget to upvote
and Accept as answer
if the reply is helpful--