Showing posts with label export distribution group members to csv office 365. Show all posts
Showing posts with label export distribution group members to csv office 365. Show all posts

Tuesday 25 October 2016

Exporting DLs with Last modify date, Date created, DL members, Members display name etc. Details in Office365 server using PowerShell.

Or, PowerShell script to export DLs in Office365 server containing details like Last Modify, Date Created, DL Members, Members Display Name, Owners etc...

Descriptions: Sometime you may need to export the DLs with their last modify date, members list and creation date for audit or inventory purpose.  You can use below PowerShell command to get these details exported in an .CSV file.

Note: Please understand the risk before executing any commands/scripts.

Steps:
Login to Office365 Server Admin PowerShell Console with administrative rights.

Copy all script section contents and run that on powershell to get the DLs details as explained above. You can change the yellow marked path and file name if you want results to be exported to some other path and with some other file name as per your requirements.

-----------------------------------------------------------------------------------------------------------------------
#Prepare Output file with headers
Out-File -FilePath d:\new.csv -InputObject "Distribution Group DisplayName,Distribution Group Email,When Created,Last Modified,Owner,Member DisplayName, Member Email, Member Type" -Encoding UTF8


#Get all Distribution Groups from Office 365
$objDistributionGroups = Get-DistributionGroup -ResultSize Unlimited

#Iterate through all groups, one at a time    
Foreach ($objDistributionGroup in $objDistributionGroups)
{    
               
                write-host "Processing $($objDistributionGroup.DisplayName)..."

                #Get members of this group
                $objDGMembers = Get-DistributionGroupMember -Identity $($objDistributionGroup.PrimarySmtpAddress)
                
                write-host "Found $($objDGMembers.Count) members..."
                
                #Iterate through each member
                Foreach ($objMember in $objDGMembers)
                {
                                Out-File -FilePath d:\new.csv -InputObject "$($objDistributionGroup.DisplayName),$($objDistributionGroup.PrimarySMTPAddress),$($objDistributionGroup.WhenCreated),$($objDistributionGroup.WhenChanged),$($objDistributionGroup.Managedby),$($objMember.DisplayName),$($objMember.PrimarySMTPAddress),$($objMember.RecipientType)" -Encoding UTF8 -append
                                write-host "`t$($objDistributionGroup.DisplayName),$($objDistributionGroup.PrimarySMTPAddress),$($objDistributionGroup.WhenCreated),$($objDistributionGroup.WhenChanged),$($objDistributionGroup.Managedby),$($objMember.DisplayName),$($objMember.PrimarySMTPAddress),$($objMember.RecipientType)"
                }
}
-----------------------------------------------------------------------------------------------------------------------

Thursday 23 June 2016

Step by step Exporting DLs from Office365 Server.

Or, How to export all DLs from Office365 server?
Or, Export Distribution List Office365 Server.

Steps:
1. Open Windows PowerShell (Run as Administrator)
2. Run below command sequentially (one by one).
----------------------------------------------------------------------------------------------------------------------------
 Set-ExecutionPolicy RemoteSigned
-----------------------------------------------------------------------------------------------------------------
 $LiveCred = Get-Credential
-----------------------------------------------------------------------------------------------------------------
 Note:  (in the pop out window, please enter Office365 global admin)  
-----------------------------------------------------------------------------------------------------------------
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri  https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic –AllowRedirection
-----------------------------------------------------------------------------------------------------------------
Import-PSSession $Session
 ----------------------------------------------------------------------------------------------------------------

(All above mentioned commands are highlighted in below screenshot sequentially)











3. Now run the below highlighted script to get the list of all DLs from your office365 server. You can    copy this script from my article 









4. Go to your D drive and search for the below file, here is the list of your all DLs.

Monday 6 June 2016

Command to export DLs members list in Office365 server?

Or, PowerShell command to exports list of DLs along with members in Office365 server.
Or, PowerShell command to export all DLs, members and owners list in Office365 Server.

Please run the below command on Office365 PowerShell windows to get the list of all DLs and It's members.
-----------------------------------------------------------------------------------------------------------------------
$Groups = Get-DistributionGroup
$Groups | ForEach-Object {
$group = $_.Name
$Owner = (Get-DistributionGroup -Identity $group).ManagedBy
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
        If($members) {
              $members=$members + ";" + $_.Name
           } Else {
              $members=$_.Name
           }
  }
New-Object -TypeName PSObject -Property @{
      GroupName = $group
      Members = $members
     Owner = $Owner
     }

} | Export-CSV "D:\Distribution-Group-Members3.csv" -NoTypeInformation -Encoding UTF8
-----------------------------------------------------------------------------------------------------------------------
Cheers..