Beans meet a small problem today, found that a Office365 group of members of the group actually did not configure the message, so that the individual users did not receive the message. To prevent this from happening again, all mail groups need to be checked. The problem is that the mail group may be nested in multiple groups, and if it's too tiring to look at it manually, write a little script sweep.
Because it is a nested group, it is natural to think of recursion. Specify a mail group, go to the members to see if the member is configured with a mailbox address, if the member is just another group, then call yourself, repeat the above steps
Function get-member{ [cmdletbinding ()] [alias ()] [outputtype ([int])] param ( # Param1 help description [parameter (mandatory= $true, valuefrompipelinebypropertyname= $true, valuefrompipeline=$ true, position=0)] [string] $name ) Begin { } Process { $a = get-distributiongroupmember $name -ErrorAction SilentlyContinue if ($a -eq $null) { return } foreach ($b in $a) { if (($b. Recipienttype -eq ' Usermailbox ') -or ($b .recipienttype -eq ' Mailcontact ') -or ($b .recipienttype -eq ' User ')) { write-host $b. Name -foregroundcolor DarkYellow } elsE{ if ($ b.primarysmtpaddress -eq "") { write-host $b. name -foregroundcolor red } else{ write-host $b .name -foregroundcolor cyan get-member $b .name } } } } end { }}
Simply test my function with the following results: Normal user (yellow), group with mail bound (blue), group with no mail bound (red)
650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M02/05/82/wKiom1mmYLah-5FKAACGDiTYGE8524.jpg "title=" 0.JPG "alt=" Wkiom1mmylah-5fkaacgdityge8524.jpg "/>
Success.
This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1961087
PowerShell recursive Query Group members