Photo by Pixabay on Pexels.com
  1. Intro
  2. Pre-requisites
  3. Script

Intro

Occasionally for cleanup, you may need to fetch membership of all room list and room mailbox. You can run this code in Exchange Online PowerShell module.

Pre-requisites

  • Exchange Online Module Installed on your Machine.
  • Minimum Read only Permission to fetch Exchange Online Objects.

Script

# Import the required module for Exchange Online
Import-Module ExchangeOnlineManagement

# Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName Your_UPN_Here -ShowProgress $true

# Define the path to the text file
$groups = Get-DistributionGroup -RecipientTypeDetails roomlist | select PrimarySmtpAddress

# Define the path to the output CSV file
$outputCsvPath = "$([Environment]::GetFolderPath('Desktop'))\Roomoutput.csv"

# Initialize an array to hold the results
$results = @()

# For each group
foreach ($group in $groups.PrimarySmtpAddress) {
    # Get the group's membership
    $members = Get-DistributionGroupMember -Identity $group

    # For each member
    foreach ($member in $members) {
        # Create a custom object
        $obj = New-Object PSObject
        $obj | Add-Member -MemberType NoteProperty -Name "GroupEmail" -Value $group
        $obj | Add-Member -MemberType NoteProperty -Name "Member" -Value $member.PrimarySmtpAddress
        $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $member.DisplayName
        $obj | Add-Member -MemberType NoteProperty -Name "HiddenFromAddressListsEnabled" -Value $member.HiddenFromAddressListsEnabled
        $obj | Add-Member -MemberType NoteProperty -Name "RecipientTypeDetails" -Value $member.RecipientTypeDetails
        # Add the custom object to the results
        $results += $obj
    }
}

# Export the results to a CSV file
$results | Export-Csv -Path $outputCsvPath -NoTypeInformation

# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false

Thank you for reading