Showing posts with label powershell export distribution list members to csv. Show all posts
Showing posts with label powershell export distribution list members to csv. Show all posts

Sunday 28 May 2017

Adding all Distribution List to a single Distribution List O365 PowerShell

Or, Making all DLs the member of a Global DL in O365
Or, How to add all DLs to a single global DL
Or, Creating a global DL containing all other DLs as member

Descriptions: In this article we are going to learn “How to add all other DLs in a Global DL member list”. Guys, this is something very common requirement across all type of organizations where people want to have a DL containing all other small DLs as a member, so that a Single mail can be sent to everyone by sending that to one DL instead of sending that to multiple DLs.

Yes, there is another way to achieve this requirement and that it creating a Dynamic DL which may by default contain all active mailboxes/users as a member. But, we will discuss about this latter in a separate detailed article.

Steps:
Connect to office365 server PowerShell admin console with administrative privilege.

Run below command to export all the DLs in to a CSV file
Get-DistributionGroup -ResultSize unlimited | select displayname,PrimarySmtpAddress | Export-CSV d:\temp\DLs.csv

Run below command to import and add all the DLs to specified global DL
Import-Csv D:\temp\DLs.csv | foreach {Add-DistributionGroupMember -Identity allDLs@domian.com -Member $_.displayname}

IMP Notes:
1. You can change the path as per your environment for exporting and importing the CSV file.
2. Do not modify anything in the exported CSV file.
3. DLs whichever are exported in the CSV file, would be added to the specified global DL. In my case it is allDLs@domain.com

Cheers, please write me back if you have any query or feedback.


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..