Guest users in office 365

HASSAN BIN NASIR DAR 306 Reputation points
2021-10-13T13:01:32.153+00:00

Hi,

I have number of guest users in office 365. Each guest user is member of different multiple groups.

I want to see the list of all guest users and their groups. After that the complete information should be export in excel file. thanks

Regards

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,163 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,383 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Marilee Turscak-MSFT 33,706 Reputation points Microsoft Employee
    2021-10-13T18:46:26.527+00:00

    Hi @HASSAN BIN NASIR DAR ,

    The best option for you is to use something like this script that queries all of the guest users and their group membership:

    To query the guest users, you can use:

    Get-AzureADUser -All $true -Filter "UserType -eq 'Guest'"  
    

    OR

    Get-AzureADUser -Filter "UserType eq 'Guest'" | select DisplayName, Mail  
    

    To export the users to a CSV file you can use:

    Get-AzureADUser -Filter "UserType eq 'Guest'" | select DisplayName, Mail | Export-Csv guests.csv -NoTypeInformation      
    

    Then you can use Get-AzureADUserMembership for individual users and run a ForEach loop to get it for everyone.

    The most straightforward thing to do would be to follow the blog post, Export Office 365 Guest User Report with their Membership, and use the accompanying GetUserReport.ps1 script.

    Hope this helps!

    https://o365reports.com/2020/11/12/export-office-365-guest-user-report-with-their-membership/

    0 comments No comments

  2. KyleXu-MSFT 26,206 Reputation points
    2021-10-14T06:16:42.64+00:00

    @HASSAN BIN NASIR DAR

    Install Azure AD PowerShell and connect to Azure AD first. Run it with administrator right.

    Then you could use the script below to get the result that you wanted(Save this script to a .PS1 file, then run this .PS1 file after connect to Azure AD):

    $data =@()  
    $Users = Get-AzureADUser | where{$_.UserType -eq "Guest"} | select ObjectId,DisplayName  
      
    foreach ($user in $users){  
        $data+= Get-AzureADUserMembership -ObjectId $user.ObjectId | select @{Expression={$user.DisplayName};Label="User";},@{Expression={$_.DisplayName};Label="GroupName";}  
    }  
    $data | Export-Csv C:\Users\demoUser\Desktop\infor.csv -NoTypeInformation  
    

    The result:
    140410-qa-kyle-14-14-26.png
    140444-qa-kyle-14-15-47.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments