locked
Pull the report of all DL's which is Managed by and Member is same RRS feed

  • Question

  • Hello Team,

    I am developing the script which pull the report those DL's

    - DL has only one member

    - Managed by user is only one member of DL 

    - Member recipient type only Mail user or remote user (Exclude the Nested DL's from member).

    - Export the DL names

    Out-File -FilePath $OutputFile -InputObject "DL DisplayName,Email id,Member count,Managed by,Hide from GAL,WhenCreated,RecipientType,RecipientTypeDetails,MemberName," -Encoding UTF8 

    #Get all Distribution Groups from Office 365 
    $objDistributionGroups = Get-DistributionGroup -ResultSize unlimited
    #Iterate through all groups, one at a time   
      
     $countOfDL = 0

        Foreach ($objDistributionGroup in $objDistributionGroups) 
        {   
           $objDGMembers = Get-DistributionGroupMember -Identity $($objDistributionGroup.PrimarySmtpAddress) 
           $Managedby = Get-Distribution -Identity $($objDistributionGroup.Managedby) 

           $countmem =  $objDGMembers.count

    if (($countmn -eq "1") -and  ($objDGMembers -eq $Managedby) -and ($objDGMembers.RecipientTypeDetails -ne "MailUniversalSecurityGroup")

    $countOfDL = $countOfDL + 1
                    
             Out-File -FilePath $OutputFile -InputObject "$($objDistributionGroup.DisplayName),$($objDistributionGroup.PrimarySMTPAddress),$($countmem),$($objDistributionGroup.ManagedBy),$($objDistributionGroup.HiddenFromAddressListsEnabled),$($objDistributionGroup.WhenCreated),$($objDistributionGroup.RecipientType),$($objDistributionGroup.RecipientTypeDetails)," -Encoding UTF8 -append 
    }   

    }

    Its failing to get the report can you please have input on this  

     

    • Moved by Bill_Stewart Monday, April 30, 2018 8:53 PM This is not "scripts on demand"
    Thursday, December 28, 2017 4:42 AM

All replies

  • Get-DistributionGroup -ResultSize unlimited |
        ForEach-Object{
            $members = @(Get-DistributionGroupMember $_.Name)
            if($members.Count -eq 1 -and $_.Managedby -eq $members[0]){
                $_
            }
        } |
        Export-Csv $OutputFile -NoTypeInformation


    \_(ツ)_/

    Thursday, December 28, 2017 6:03 AM
  • $final = @()
    
    get-content C:\Users\Desktop\Test.txt  | Get-DistributionGroup |
        ForEach-Object{
            $members = @(Get-DistributionGroupMember $_.Name)
            if($members.Count -le 1 -and $_.Managedby -eq $members[0]){
                $_
            }
        } |
        Export-Csv $final -NoTypeInformationFile 

    Not working how do I make If condition if member recipient type only remote user or mailuser. Also unable to pull report getting error  

    Thursday, December 28, 2017 8:34 AM