Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Friday, February 12, 2021

Quick Hit: Subscribing Existing Members of a Microsoft 365 Group

Took me quite a while to find this solution so I'm just putting it out here so i can find it if I need it again.

The Problem: I re-purposed an O365 group in my Azure AD console, one that was already configured with the dynamic query I needed. Unfortunately, I didn't realize that, by default, members of O365 groups don't receive a copy of emails sent to the group in their personal mailbox. The messages just go to the group mailbox.

After doing some research, I reconfigured the O365 group to automatically "subscribe" new members, but that doesn't change the subscription status of the existing members. A lot of the "solutions" I found on the internet involved enabling the "Subscribe new members" flag and then removing all existing members and then adding them back to the group so that they would be subscribed. While that method probably works, it's not very elegant. There must be another way to accomplish my goal.

Turns out there is, and here it is: 

$group = Get-UnifiedGroup -Identity "Group_Name_or_Email_Address"

# Get list of all members
$members = Get-UnifiedGroupLinks -Identity $group.Name -LinkType Members

# Get list of all subscribers (a-ha!)
$subscribers = Get-UnifiedGroupLinks -Identity $group.Name -LinkType Subscribers

# Subscribe all members not subscribed
foreach ($member in $members) { 
    If ($member.Name -notin $subscribers.Name) {
        Write-Host "Adding $($member.Name)."
        Add-UnifiedGroupLinks -Identity $group.Name -LinkType Subscribers -Links $member.Name
    } else {
        Write-Host "$($member.Name) is already subscribed."
    }
}
# Done!

Almost all of the solutions I found online took the "remove everyone and then add them back again" approach, and maybe that's because that was the only solution at the time. Microsoft is always making changes and introducing new features and functionality, so maybe this PowerShell-based solution was not available until recently. Anyway, it works and it's a pretty simple solution.

Friday, December 27, 2019

Unable to Recreate a Recently Deleted O365 Group

A colleague recently came to me with a problem. One of our "teams" had somehow managed to delete the dynamic Office 365 group that their Team was based on. He was attempting to recreate the group, but each attempt failed with the following error.


New-AzureADMSGroup : Error occurred while executing NewMSGroup
Code: Request_BadRequest
Message: Another object with the same value for property mailNickname already exists.


To this point, I haven't worked with O365 groups very much (or at all), so it was an interesting problem to dig into.

Since the error mentions the 'mailNickname' attribute and I know that's an attribute of the O365 group, it was pretty obvious that the group was still out there somewhere, interfering with the creation of the new group. So, it seemed obvious that the group was only soft-deleted. I just had to figure out how to find it and delete it permanently.

And before anyone points it out, yes, I know that we could have just restored the old group - and that's probably what we should have done. But part of me was curious to confirm that getting rid of the old group would eliminate the error we were getting when we tries to create the new group.

Initially, I was unable to locate the deleted group in the Azure AD portal. All of the team names start with "FLD", and while searching for that string did reveal some deleted groups, the one I was looking for was not among them. Nor was it among the active groups (had to check). Hmmm.

After a bit of googling, I learned of the Get-AzureADMSDeletedGroup command, part of the AzureAD powershell module. That command, with no arguments, returns a list of all soft-deleted groups, and it was on that list that I found my missing group. The default output of Get-AzureADMSDeletedGroup shows the Id, DisplayName, and Description of the group, and this is when I discovered that my colleague had not been consistent with our O365 team group naming. I happened to find the group I was looking for by looking for the unique number in the name. While the object name (which was not in the output from Get-AzureADMSDeletedGroup) may have started with "FLD", the DisplayName did not. But both the name and the DisplayName had that same unique number, which allowed me to locate the group, which also revealed that he DisplayName started with "District", not the expected "FLD".

At this point, I could have deleted the group by using the Remove-AzureADMSDeletedDirectoryObject command, which takes the group's unique ID string. However, now that I located the group in powershell, I wanted to find it in the Azure AD console, too. Based on what I saw in powershell, I searched the deleted groups using "District", and there it was! Right there in the Azure console, I selected the group and permanently deleted it.

Switching back to powershell, I again tried to pull up the details of the group, but this time that failed because the object had been deleted. So then I entered the command that my colleague had tried to run, to recreate the group, and that also succeeded. Problem solved.

New-AzureADMSGroup `
   -DisplayName "FLD DIST 0806" `
   -Description "District 0806 (dynamic)" `
   -MailEnabled $True `
   -SecurityEnabled $True `
   -MailNickname "FLDDIST0806DYN" `
   -GroupTypes "DynamicMembership", "Unified" `
   -MembershipRule "(User.extensionAttribute13 -eq ""0806"")" `
   -MembershipRuleProcessingState "On" `
   -Visibility "Private"

Bye.