PowerShell recursive Query Group members

Source: Internet
Author: User
Tags all mail

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.