Link to home
Start Free TrialLog in
Avatar of ajdratch
ajdratch

asked on

Export Distribution lists from exchange to Office 365

I am trying to find a powershell script to export all distribution lists from on-premise Exchange 2010 and import them into Office 365. I want to keep these as distribution list, I do not want to convert them to groups.

Is there a way to do this?
Avatar of Michael B. Smith
Michael B. Smith
Flag of United States of America image

It takes several steps. This website has a really good description of the steps and some PowerShell assist: http://blogs.catapultsystems.com/thernandez/archive/2015/09/16/migrate-distribution-groups-from-exchange-on-premise-to-exchange-online/
ajdratch-
Are you in a hybrid scenario?
If so your distribution groups are also showing up already in o365.  If that is the case and you want to create all your dls directly on o365- we 1. Pull all the info for the dls and their members, then 2. move the dls to an OU that doesn't sync with o365 so they will disappear from o365

Create a folder named Temp on your c: drive



1. You want to pull all the distributiongroups getting their names,displayname alias,and smtp address

Get-DistributionGroup -ResultSize Unlimited | Select Name,DisplayName,Alias,PrimarySmtpAddress,ManagedBy | Export-csv 'c:\temp\o365grps.csv' -notypeinformation

2.  Now you want to get all group members of these distributiongroups from the .csv we just created

Import-Csv 'c:\temp\o365grps.csv' | %{$name=$_.Name; Get-DistributionGroupMember $_.Name | Select PrimarySmtpAddress | Export-csv 'c:\temp\$name.csv' -notypeinformation}

If in a hybrid scenario- now move all your on premise dls to an OU that is not syncing with o365.   Wait until you don't see your dls in o365 anymore now recreate the dls in the following steps.

Log in to o365 via powershell- run the following command to create all your dls back

Import-Csv 'c:\temp\o365grps.csv' |  %{New-DistributionGroup -Name $_.Name  -DisplayName $_.DisplayName -Alias $_.Alias -PrimarySmtpAddress $_.PrimarySMTPAddress -ManagedBy $_.managedby}

We now have all the groups created in o365 so now we need to add the members back to the groups
*Remember- all the groupmembers have been exported to .csv files matching the group Name*

2 options-
a)- add the groupmembers back with a command doing them one by one
     Import-csv "C:\temp\oneofthgroupsname.csv"  | %{Add-DistributionGroupMember nameofgroupthatcorrespondswiththecsv -member $_.PrimarysmtpAddress}

OR

We bulk add all the members to all the dls with the below steps and powershell command
1.   Go to the .csv c:\temp\o365grps.csv and a create another header named Path
2.   In each Row that has a group name input the path to where the .csv that contains the groupmembers is located
example  DistributionGroup1 now has all the groupmembers in the .csv c:\temp\DistributionGroup1.csv
You will put c:\temp\DistributionGroup1.csv in the path column for that DistributionGroup.  Set the path for all your groupmembers for their Distribution groups.  

Now put the below in a  notepad, save it to c:\temp as Addo365members.ps1  

$csv = import-csv 'c:\temp\o365grps.csv'
foreach ($c in $csv) {
Import-csv $c.path | %{Add-DistributionGroupMember $c.name -Member $_.PrimarySmtpAddress}
}


cd to c:temp then type      .\Addo365members.ps1   press enter

All your dls will now populate with their members
Avatar of ajdratch
ajdratch

ASKER

I am not in hybrid mode. I saw the link that Michael sent but it lost me at the beginning of step two "Clean file from export 1"

It says to Create “NEW” values. Insert columns after the following (Name, Alias, DisplayName, PrimarySmtpAddress), and prefix column header with “NEW” by using following formula.

I created the new column headings by typing them in. I did not use a formula

It then says to "copy the formula down through data, so that all data is prefixed with "NEW." I am not sure what I am supposed to do here since I don't have a formula to use.  I'm not sure what is supposed to be in the fields under the NEW columns that i created.
Fair enough if you are not in a hybrid mode then follow my steps.  You don't have to worry about moving the on prem dls to an OU that is not syncing.
I am using the directory E:\DistributionExport. In step 2 I run
Import-Csv 'E:\DistributionExport\o365grps.csv' | %{$name=$_.Name; Get-DistributionGroupMember $_.Name | Select PrimarySmtpAddress | Export-csv 'E:\DistributionExport\$name.csv' -notypeinformation}

The $name.csv file is empty
Is your file o365grps.csv populated with info?
Yes, all five columns  are populated
When you did the export  >Export-csv 'E:\DistributionExport\$name.csv' -notypeinformation}<  It should have made .csv files with the names of your distribution groups.  These .csv files will contain your groupmembers.  It did not create any .csv files?
The syntax may have needed a few spaces for the name area, try the below

Import-Csv 'E:\DistributionExport\o365grps.csv' | %{$name = $_.Name; Get-DistributionGroupMember $_.Name | Select PrimarySmtpAddress | Export-csv 'E:\DistributionExport\$name.csv' -notypeinformation}
Got the same result. The file $name.csv gets created however it is empty - zero bytes
Fair enough let's pick a different field

Import-Csv 'E:\DistributionExport\o365grps.csv' | %{$Alias = $_.Alias; Get-DistributionGroupMember $_.Alias | Select PrimarySmtpAddress | Export-csv 'E:\DistributionExport\$Alias.csv' -notypeinformation}
Same thing. The file $Alias,csv was created but zero bytes
I've used that so many times without issue.  Let's try it another way.

Import-Csv 'E:\DistributionExport\o365grps.csv' | %{Get-DistributionGroupMember $_.Name | Select PrimarySmtpAddress | Export-csv 'E:\DistributionExport\$_.name.csv' -notypeinformation}
Same results. The file is created but it is zero bytes.
Let's test on one group- Get the Name or alias of one of the groups

Get-DistributionGroupMember 'inputnameoraliasofgroup'  | Select PrimarySmtpAddress | Export-csv 'E:\DistributionExport\inputnameoraliasofgroup.csv' -notypeinformation


Were you running the command on prem Exchange?
That did work. I have a list of PrimarySmtpAddress for the one distribution group
Please send a screenshot of one complete row from your .csv o365grps. with the headers...top row is sufficient...with the headers
Screenshot is attached
Capture.JPG
The .csv you have looks good.  Are you running the command in on prem Exchange management Shell?

Import-csv 'E:\DistributionExport\o365grps.csv' | %{ $name = $_.Name; Get-DistributionGroupMember $_.Name | Select PrimarySmtpAddress | Export-csv "E:\DistributionExport\$name.csv" -notypeinformation }
I am running it on the on-premise Exchange server. I ran the script you just posted and it created a file for each distribution group with the members
Finally
Ok now that you have pulled the information for the groups and its members...log in to o365 via powershelll and let's create all your groups at one time.

Import-Csv 'E:\DistributionExport\o365grps.csv' |  %{New-DistributionGroup -Name $_.Name  -DisplayName $_.DisplayName -Alias $_.Alias -PrimarySmtpAddress $_.PrimarySMTPAddress -ManagedBy $_.managedby}
I'm getting this error for each file

Couldn't find object
"Microsoft.Exchange.Data.Directory.ADMultiValuedProperty`1[Microsoft.Exchange.Data.Directory.ADObjectId]". Please make
sure that it was spelled correctly or specify a different object.
    + CategoryInfo          : NotSpecified: (:) [], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : [Server=BLUPR16MB0450,RequestId=320c9f90-b533-42f7-a225-50f16adbbfa4,TimeStamp=10/14/201
   8 8:41:50 PM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 289573BB
    + PSComputerName        : outlook.office365.com
When I run the command Import-PSSession $Session -DisableNameChecking I get the following output

Import-PSSession : No command proxies have been created, because all of the requested remote commands would shadow
existing local commands.  Use the AllowClobber parameter if you want to shadow existing local commands.
At line:1 char:1
+ Import-PSSession $Session -DisableNameChecking
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Import-PSSession], ArgumentException
    + FullyQualifiedErrorId : ErrorNoCommandsImportedBecauseOfSkipping,Microsoft.PowerShell.Commands.ImportPSSessionCo
   mmand
Copy the below to notepad and save in the folder of your choice as o365connect.ps1

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxyMethod=RPS -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

Then cd to the folder and type in      .\o365connect.ps1 and press enter
This is the entire error after that runs. I did copy all the files to a computer that has Windows Azure powershell.  That is why the folder is d:\temp\dl

WARNING: Proxy creation has been skipped for the following command: 'Add-AvailabilityAddressSpace,
Add-DistributionGroupMember, Add-MailboxFolderPermission, Add-MailboxLocation, Add-MailboxPermission,
Add-ManagementRoleEntry, Add-PublicFolderClientPermission, Add-RecipientPermission, Add-RoleGroupMember,
Add-UnifiedGroupLinks, Approve-ElevatedAccessRequest, Clear-ActiveSyncDevice, Clear-MobileDevice,
Clear-TextMessagingAccount, Compare-TextMessagingVerificationCode, Complete-MigrationBatch,
ConvertFrom-ExoJobData.ps1, Delete-QuarantineMessage, Deny-ElevatedAccessRequest, Disable-AntiPhishRule, Disable-App,
Disable-HostedContentFilterRule, Disable-InboxRule, Disable-JournalArchiving, Disable-JournalRule, Disable-Mailbox,
Disable-MailPublicFolder, Disable-MalwareFilterRule, Disable-OutlookProtectionRule, Disable-SweepRule,
Disable-TransportRule, Disable-UMAutoAttendant, Disable-UMCallAnsweringRule, Disable-UMIPGateway, Disable-UMMailbox,
Enable-AntiPhishRule, Enable-App, Enable-HostedContentFilterRule, Enable-InboxRule, Enable-JournalRule,
Enable-Mailbox, Enable-MailPublicFolder, Enable-MalwareFilterRule, Enable-OrganizationCustomization,
Enable-OutlookProtectionRule, Enable-SweepRule, Enable-TransportRule, Enable-UMAutoAttendant,
Enable-UMCallAnsweringRule, Enable-UMIPGateway, Enable-UMMailbox, Export-MailboxDiagnosticLogs,
Export-MigrationReport, Export-QuarantineMessage, Export-TransportRuleCollection, Export-UMCallDataRecord,
Export-UMPrompt, Get-AcceptedDomain, Get-ActiveSyncDevice, Get-ActiveSyncDeviceAccessRule, Get-ActiveSyncDeviceClass,
Get-ActiveSyncDeviceStatistics, Get-ActiveSyncMailboxPolicy, Get-ActiveSyncOrganizationSettings,
Get-AddressBookPolicy, Get-AdminAuditLogConfig, Get-AdministrativeUnit, Get-AdvancedThreatProtectionDocumentDetail,
Get-AdvancedThreatProtectionDocumentReport, Get-AntiPhishPolicy, Get-AntiPhishRule, Get-App,
Get-ApplicationAccessPolicy, Get-ATPTotalTrafficReport, Get-AuditConfig, Get-AuditConfigurationPolicy,
Get-AuditConfigurationRule, Get-AuditLogSearch, Get-AuthServer, Get-AvailabilityAddressSpace, Get-AvailabilityConfig,
Get-BlockedSenderAddress, Get-CalendarDiagnosticAnalysis, Get-CalendarDiagnosticLog, Get-CalendarDiagnosticObjects,
Get-CalendarNotification, Get-CalendarProcessing, Get-CalendarViewDiagnostics, Get-CASMailbox, Get-CASMailboxPlan,
Get-ClientAccessRule, Get-Clutter, Get-CompliancePolicyFileSyncNotification, Get-CompliancePolicySyncNotification,
Get-ComplianceTag, Get-ComplianceTagStorage, Get-ConnectionByClientTypeDetailReport, Get-ConnectionByClientTypeReport,
 Get-ConnectSubscription, Get-Contact, Get-CsActiveUserReport, Get-CsAVConferenceTimeReport,
Get-CsClientDeviceDetailReport, Get-CsClientDeviceReport, Get-CsConferenceReport, Get-CsP2PAVTimeReport,
Get-CsP2PSessionReport, Get-CsPSTNConferenceTimeReport, Get-CsPSTNUsageDetailReport, Get-CsUserActivitiesReport,
Get-CsUsersBlockedReport, Get-DataEncryptionPolicy, Get-DataRetentionReport, Get-DeviceComplianceDetailsReport,
Get-DeviceComplianceDetailsReportFilter, Get-DeviceCompliancePolicyInventory, Get-DeviceComplianceReportDate,
Get-DeviceComplianceSummaryReport, Get-DeviceComplianceUserInventory, Get-DeviceComplianceUserReport,
Get-DeviceConditionalAccessPolicy, Get-DeviceConditionalAccessRule, Get-DeviceConfigurationPolicy,
Get-DeviceConfigurationRule, Get-DevicePolicy, Get-DeviceTenantPolicy, Get-DeviceTenantRule, Get-DistributionGroup,
Get-DistributionGroupMember, Get-DkimSigningConfig, Get-DlpKeywordDictionary,
Get-DlpSensitiveInformationTypeRulePackage, Get-DlpSiDetectionsReport, Get-DynamicDistributionGroup,
Get-ElevatedAccessApprovalPolicy, Get-ElevatedAccessAuthorization, Get-ElevatedAccessRequest,
Get-EligibleDistributionGroupForMigration, Get-EmailAddressPolicy, Get-FailedContentIndexDocuments,
Get-FederatedOrganizationIdentifier, Get-FederationInformation, Get-FederationTrust, Get-FfoMigrationReport,
Get-FocusedInbox, Get-Group, Get-GroupActivityReport, Get-GroupMailbox, Get-HistoricalSearch,
Get-HostedConnectionFilterPolicy, Get-HostedContentFilterPolicy, Get-HostedContentFilterRule,
Get-HostedOutboundSpamFilterPolicy, Get-HotmailSubscription, Get-HybridMailflow, Get-HybridMailflowDatacenterIPs,
Get-ImapSubscription, Get-InboundConnector, Get-InboxRule, Get-IntraOrganizationConfiguration,
Get-IntraOrganizationConnector, Get-IRMConfiguration, Get-JournalRule, Get-LicenseVsUsageSummaryReport,
Get-LinkedUser, Get-LogonStatistics, Get-Mailbox, Get-MailboxActivityReport, Get-MailboxAuditBypassAssociation,
Get-MailboxAutoReplyConfiguration, Get-MailboxCalendarConfiguration, Get-MailboxCalendarFolder, Get-MailboxFolder,
Get-MailboxFolderPermission, Get-MailboxFolderStatistics, Get-MailboxJunkEmailConfiguration, Get-MailboxLocation,
Get-MailboxMessageConfiguration, Get-MailboxOverrideConfiguration, Get-MailboxPermission, Get-MailboxPlan,
Get-MailboxPreferredLocation, Get-MailboxRegionalConfiguration, Get-MailboxRestoreRequest,
Get-MailboxRestoreRequestStatistics, Get-MailboxSearch, Get-MailboxSpellingConfiguration, Get-MailboxStatistics,
Get-MailboxUsageDetailReport, Get-MailboxUsageReport, Get-MailboxUserConfiguration, Get-MailContact,
Get-MailDetailATPReport, Get-MailDetailMalwareReport, Get-MailDetailReport, Get-MailDetailSpamReport,
Get-MailDetailTransportRuleReport, Get-MailFilterListReport, Get-MailPublicFolder, Get-MailTrafficATPReport,
Get-MailTrafficPolicyReport, Get-MailTrafficReport, Get-MailTrafficSummaryReport, Get-MailTrafficTopReport,
Get-MailUser, Get-MalwareFilterPolicy, Get-MalwareFilterRule, Get-ManagementRole, Get-ManagementRoleAssignment,
Get-ManagementRoleEntry, Get-ManagementScope, Get-MessageCategory, Get-MessageClassification, Get-MessageRecallResult,
 Get-MessageTrace, Get-MessageTraceDetail, Get-MessageTrackingReport, Get-MigrationBatch, Get-MigrationConfig,
Get-MigrationEndpoint, Get-MigrationStatistics, Get-MigrationUser, Get-MigrationUserStatistics, Get-MobileDevice,
Get-MobileDeviceDashboardSummaryReport, Get-MobileDeviceMailboxPolicy, Get-MobileDeviceStatistics, Get-MoveRequest,
Get-MoveRequestStatistics, Get-MxRecordReport, Get-MxRecordsReport, Get-Notification,
Get-O365ClientBrowserDetailReport, Get-O365ClientBrowserReport, Get-O365ClientOSDetailReport, Get-O365ClientOSReport,
Get-OMEConfiguration, Get-OMEMessageStatus, Get-OnlineMeetingConfiguration, Get-OnPremisesOrganization,
Get-OrganizationalUnit, Get-OrganizationConfig, Get-OrganizationRelationship, Get-OutboundConnector,
Get-OutboundConnectorReport, Get-OutlookProtectionRule, Get-OwaMailboxPolicy, Get-PartnerApplication,
Get-PartnerCustomerUserReport, Get-PerimeterConfig, Get-PerimeterMessageTrace, Get-PhishFilterPolicy, Get-Place,
Get-PopSubscription, Get-PublicFolder, Get-PublicFolderClientPermission, Get-PublicFolderItemStatistics,
Get-PublicFolderMailboxDiagnostics, Get-PublicFolderMailboxMigrationRequest,
Get-PublicFolderMailboxMigrationRequestStatistics, Get-PublicFolderMigrationRequest,
Get-PublicFolderMigrationRequestStatistics, Get-PublicFolderStatistics, Get-QuarantineMessage,
Get-QuarantineMessageHeader, Get-RbacDiagnosticInfo, Get-Recipient, Get-RecipientPermission,
Get-RecipientStatisticsReport, Get-RemoteDomain, Get-ReportExecutionInstance, Get-ReportSchedule,
Get-ReportScheduleList, Get-ResourceConfig, Get-RetentionEvent, Get-RetentionPolicy, Get-RetentionPolicyTag,
Get-RMSTemplate, Get-RMSTrustedPublishingDomain, Get-RoleAssignmentPolicy, Get-RoleGroup, Get-RoleGroupMember,
Get-SCInsights, Get-ScorecardClientDeviceReport, Get-ScorecardClientOSReport, Get-ScorecardClientOutlookReport,
Get-ScorecardMetricsReport, Get-SearchDocumentFormat, Get-SecurityPrincipal, Get-SendAddress, Get-SenderPermission,
Get-ServiceDeliveryReport, Get-ServiceStatus, Get-SharingPolicy, Get-SiteMailbox, Get-SiteMailboxDiagnostics,
Get-SiteMailboxProvisioningPolicy, Get-SmimeConfig, Get-SPOActiveUserReport, Get-SpoofMailReport,
Get-SPOSkyDriveProDeployedReport, Get-SPOSkyDriveProStorageReport, Get-SPOTeamSiteDeployedReport,
Get-SPOTeamSiteStorageReport, Get-SPOTenantStorageMetricReport, Get-StaleMailboxDetailReport, Get-StaleMailboxReport,
Get-Subscription, Get-SupervisoryReviewPolicyReport, Get-SupervisoryReviewPolicyV2, Get-SupervisoryReviewReport,
Get-SupervisoryReviewRule, Get-SweepRule, Get-SyncConfig, Get-SyncRequest, Get-SyncRequestStatistics,
Get-TextMessagingAccount, Get-ToolInformation, Get-TransportConfig, Get-TransportRule, Get-TransportRuleAction,
Get-TransportRulePredicate, Get-UMAutoAttendant, Get-UMCallAnsweringRule, Get-UMCallDataRecord,
Get-UMCallSummaryReport, Get-UMDialPlan, Get-UMHuntGroup, Get-UMIPGateway, Get-UMMailbox, Get-UMMailboxConfiguration,
Get-UMMailboxPIN, Get-UMMailboxPlan, Get-UMMailboxPolicy, Get-UMPhoneSession, Get-UnifiedAuditSetting,
Get-UnifiedGroup, Get-UnifiedGroupLinks, Get-User, Get-UserPhoto, Import-ContactList, Import-RecipientDataProperty,
Import-RMSTrustedPublishingDomain, Import-TransportRuleCollection, Import-UMPrompt, New-ActiveSyncDeviceAccessRule,
New-ActiveSyncMailboxPolicy, New-AdminAuditLogSearch, New-AntiPhishPolicy, New-AntiPhishRule, New-App,
New-ApplicationAccessPolicy, New-AvailabilityConfig, New-ClientAccessRule, New-CompliancePolicySyncNotification,
New-ConnectSubscription, New-DistributionGroup, New-DkimSigningConfig, New-DynamicDistributionGroup,
New-ElevatedAccessRequest, New-EmailAddressPolicy, New-HostedConnectionFilterPolicy, New-HostedContentFilterPolicy,
New-HostedContentFilterRule, New-HotmailSubscription, New-ImapSubscription, New-InboundConnector, New-InboxRule,
New-IntraOrganizationConnector, New-JournalRule, New-Mailbox, New-MailboxAuditLogSearch, New-MailboxFolder,
New-MailboxRestoreRequest, New-MailboxSearch, New-MailContact, New-MailMessage, New-MailUser, New-MalwareFilterPolicy,
 New-MalwareFilterRule, New-ManagementRole, New-ManagementRoleAssignment, New-ManagementScope,
New-MessageClassification, New-MigrationBatch, New-MigrationEndpoint, New-MobileDeviceMailboxPolicy, New-MoveRequest,
New-OnPremisesOrganization, New-OrganizationRelationship, New-OutboundConnector, New-OutlookProtectionRule,
New-OwaMailboxPolicy, New-PartnerApplication, New-PopSubscription, New-PrivilegedIdentityManagementRequest,
New-ProtectionServicePolicy, New-PublicFolder, New-PublicFolderMigrationRequest, New-RemoteDomain, New-ReportSchedule,
 New-RetentionPolicy, New-RetentionPolicyTag, New-RoleAssignmentPolicy, New-RoleGroup, New-SchedulingMailbox,
New-SharingPolicy, New-SiteMailbox, New-SiteMailboxProvisioningPolicy, New-Subscription, New-SweepRule,
New-SyncMailPublicFolder, New-SyncRequest, New-TransportRule, New-UMAutoAttendant, New-UMCallAnsweringRule,
New-UMDialPlan, New-UMHuntGroup, New-UMIPGateway, New-UMMailboxPolicy, New-UnifiedGroup, Preview-QuarantineMessage,
Release-QuarantineMessage, Remove-ActiveSyncDevice, Remove-ActiveSyncDeviceAccessRule, Remove-ActiveSyncMailboxPolicy,
 Remove-AntiPhishPolicy, Remove-AntiPhishRule, Remove-App, Remove-ApplicationAccessPolicy,
Remove-AuditConfigurationPolicy, Remove-AuditConfigurationRule, Remove-AuditStubFolder,
Remove-AvailabilityAddressSpace, Remove-AvailabilityConfig, Remove-BlockedSenderAddress, Remove-CalendarEvents,
Remove-ClientAccessRule, Remove-CompliancePolicyFileSyncNotification, Remove-CompliancePolicySyncNotification,
Remove-ConnectSubscription, Remove-DistributionGroup, Remove-DistributionGroupMember, Remove-DynamicDistributionGroup,
 Remove-EmailAddressPolicy, Remove-HostedConnectionFilterPolicy, Remove-HostedContentFilterPolicy,
Remove-HostedContentFilterRule, Remove-HybridConfiguration, Remove-InboundConnector, Remove-InboxRule,
Remove-IntraOrganizationConnector, Remove-JournalRule, Remove-Mailbox, Remove-MailboxFolderPermission,
Remove-MailboxLocation, Remove-MailboxPermission, Remove-MailboxRestoreRequest, Remove-MailboxSearch,
Remove-MailboxUserConfiguration, Remove-MailContact, Remove-MailUser, Remove-MalwareFilterPolicy,
Remove-MalwareFilterRule, Remove-ManagementRole, Remove-ManagementRoleAssignment, Remove-ManagementRoleEntry,
Remove-ManagementScope, Remove-MessageClassification, Remove-MigrationBatch, Remove-MigrationEndpoint,
Remove-MigrationUser, Remove-MobileDevice, Remove-MobileDeviceMailboxPolicy, Remove-MoveRequest,
Remove-OnPremisesOrganization, Remove-OrganizationRelationship, Remove-OutboundConnector,
Remove-OutlookProtectionRule, Remove-OwaMailboxPolicy, Remove-PartnerApplication, Remove-PublicFolder,
Remove-PublicFolderClientPermission, Remove-PublicFolderMigrationRequest, Remove-RecipientPermission,
Remove-RemoteDomain, Remove-ReportSchedule, Remove-RetentionPolicy, Remove-RetentionPolicyTag,
Remove-RMSTrustedPublishingDomain, Remove-RoleAssignmentPolicy, Remove-RoleGroup, Remove-RoleGroupMember,
Remove-SharingPolicy, Remove-Subscription, Remove-SweepRule, Remove-SyncMailPublicFolder, Remove-SyncRequest,
Remove-TransportRule, Remove-UMAutoAttendant, Remove-UMCallAnsweringRule, Remove-UMDialPlan, Remove-UMHuntGroup,
Remove-UMIPGateway, Remove-UMMailboxPolicy, Remove-UnifiedGroup, Remove-UnifiedGroupLinks, Remove-UserPhoto,
Resume-MailboxRestoreRequest, Resume-MoveRequest, Resume-PublicFolderMailboxMigrationRequest,
Resume-PublicFolderMigrationRequest, Resume-SyncRequest, Revoke-ElevatedAccessAuthorization, Rotate-DkimSigningConfig,
 Search-AdminAuditLog, Search-MailboxAuditLog, Search-MessageTrackingReport, Search-UnifiedAuditLog,
Send-TextMessagingVerificationCode, Set-AcceptedDomain, Set-ActiveSyncDeviceAccessRule, Set-ActiveSyncMailboxPolicy,
Set-ActiveSyncOrganizationSettings, Set-AdminAuditLogConfig, Set-AntiPhishPolicy, Set-AntiPhishRule, Set-App,
Set-ApplicationAccessPolicy, Set-AvailabilityConfig, Set-CalendarNotification, Set-CalendarProcessing, Set-CASMailbox,
 set-CASMailboxPlan, Set-ClientAccessRule, Set-Clutter, Set-ConnectSubscription, Set-Contact,
Set-DataEncryptionPolicy, Set-DistributionGroup, Set-DkimSigningConfig, Set-DynamicDistributionGroup,
Set-ElevatedAccessRequest, Set-EmailAddressPolicy, Set-FederatedOrganizationIdentifier, Set-FocusedInbox, Set-Group,
Set-GroupMailbox, Set-HostedConnectionFilterPolicy, Set-HostedContentFilterPolicy, Set-HostedContentFilterRule,
Set-HostedOutboundSpamFilterPolicy, Set-HotmailSubscription, Set-HybridMailflow, Set-ImapSubscription,
Set-InboundConnector, Set-InboxRule, Set-IntraOrganizationConnector, Set-IRMConfiguration, Set-JournalRule,
Set-LinkedUser, Set-Mailbox, Set-MailboxAuditBypassAssociation, Set-MailboxAutoReplyConfiguration,
Set-MailboxCalendarConfiguration, Set-MailboxCalendarFolder, Set-MailboxFolderPermission,
Set-MailboxJunkEmailConfiguration, Set-MailboxLocation, Set-MailboxMessageConfiguration, Set-MailboxPlan,
Set-MailboxRegionalConfiguration, Set-MailboxRestoreRequest, Set-MailboxSearch, Set-MailboxSpellingConfiguration,
Set-MailContact, Set-MailPublicFolder, Set-MailUser, Set-MalwareFilterPolicy, Set-MalwareFilterRule,
Set-ManagementRoleAssignment, Set-ManagementRoleEntry, Set-ManagementScope, Set-MessageClassification,
Set-MigrationBatch, Set-MigrationConfig, Set-MigrationEndpoint, Set-MigrationUser, Set-MobileDeviceMailboxPolicy,
Set-MoveRequest, Set-Notification, Set-OMEConfiguration, Set-OMEMessageRevocation, Set-OnPremisesOrganization,
Set-Organization, Set-OrganizationConfig, Set-OrganizationRelationship, Set-OutboundConnector,
Set-OutlookProtectionRule, Set-OwaMailboxPolicy, Set-PartnerApplication, Set-PerimeterConfig, Set-PhishFilterPolicy,
Set-Place, Set-PopSubscription, Set-ProtectionServicePolicy, Set-PublicFolder,
Set-PublicFolderMailboxMigrationRequest, Set-PublicFolderMigrationRequest, Set-RemoteDomain, Set-ReportSchedule,
Set-ResourceConfig, Set-RetentionPolicy, Set-RetentionPolicyTag, Set-RMSTemplate, Set-RMSTrustedPublishingDomain,
Set-RoleAssignmentPolicy, Set-RoleGroup, Set-SharingPolicy, Set-SiteMailbox, Set-SiteMailboxProvisioningPolicy,
Set-SmimeConfig, Set-SweepRule, Set-SyncRequest, Set-TextMessagingAccount, Set-TransportConfig, Set-TransportRule,
Set-UMAutoAttendant, Set-UMCallAnsweringRule, Set-UMDialPlan, Set-UMIPGateway, Set-UMMailbox,
Set-UMMailboxConfiguration, Set-UMMailboxPIN, Set-UMMailboxPolicy, Set-UnifiedAuditSetting, Set-UnifiedGroup,
Set-User, Set-UserPhoto, Start-AuditAssistant, Start-HistoricalSearch, Start-ManagedFolderAssistant,
Start-MigrationBatch, Start-MigrationUser, Start-UMPhoneSession, Stop-HistoricalSearch, Stop-MigrationBatch,
Stop-MigrationUser, Stop-UMPhoneSession, Suspend-MailboxRestoreRequest, Suspend-MoveRequest,
Suspend-PublicFolderMailboxMigrationRequest, Suspend-PublicFolderMigrationRequest, Suspend-SyncRequest,
Test-ApplicationAccessPolicy, Test-ClientAccessRule, Test-DataEncryptionPolicy, Test-IRMConfiguration,
Test-MAPIConnectivity, Test-MigrationServerAvailability, Test-OAuthConnectivity, Test-OrganizationRelationship,
Test-SiteMailbox, Troubleshoot-AgendaMail, Undo-SoftDeletedMailbox, Undo-SoftDeletedUnifiedGroup,
Update-DistributionGroupMember, Update-HybridConfiguration, Update-PublicFolderMailbox, Update-Recipient,
Update-RoleGroupMember, Update-SiteMailbox, Upgrade-DistributionGroup, Validate-OutboundConnector,
Validate-RetentionRuleQuery, Write-AdminAuditLog', because it would shadow an existing local command.  Use the
AllowClobber parameter if you want to shadow existing local commands.
Import-PSSession : No command proxies have been created, because all of the requested remote commands would shadow
existing local commands.  Use the AllowClobber parameter if you want to shadow existing local commands.
At D:\temp\DL\0365Connect.ps1:4 char:1
+ Import-PSSession $Session
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Import-PSSession], ArgumentException
    + FullyQualifiedErrorId : ErrorNoCommandsImportedBecauseOfSkipping,Microsoft.PowerShell.Commands.ImportPSSessionC
   ommand
If all of that came up in yellow you may already be connected.  Ok do the following
As a test do a Get-Mailbox 'whateveremailAddressyouhaveino365 | Select DisplayName,WindowsEmailAddress

If it gives you results you are already in then go to below instructions


We bulk add all the members to all the dls with the below steps and powershell command
1.   Go to the .csv c:\temp\o365grps.csv and a create another header named Path
2.   In each Row that has a group name input the path to where the .csv that contains the groupmembers is located
example  DistributionGroup1 now has all the groupmembers in the .csv c:\temp\DistributionGroup1.csv
You will put c:\temp\DistributionGroup1.csv in the path column for that DistributionGroup.  Set the path for all your groupmembers for their Distribution groups.  

Now put the below in a  notepad, save it to c:\temp as Addo365members.ps1  

$csv = import-csv 'c:\temp\o365grps.csv'
foreach ($c in $csv) {
Import-csv $c.path | %{Add-DistributionGroupMember $c.name -Member $_.PrimarySmtpAddress}
}


cd to c:temp then type      .\Addo365members.ps1   press enter

All your dls will now populate with their members
When I run Get-Mailbox 'whateveremailAddressyouhaveino365 | Select DisplayName,WindowsEmailAddress
It comes back with  >>

PS D:\temp\DL> Get-Mailbox 'whateveremailAddressyouhaveino365 | Select DisplayName,WindowsEmailAddress
>>
I missed a closing quote  use any emailaddress you have in o365 inside the quotes below

Get-Mailbox 'whateveremailAddressyouhaveino365' | Select DisplayName,WindowsEmailAddress
I do get a response from Get-Mailbox 'whateveremailAddressyouhaveino365 | Select DisplayName,WindowsEmailAddress

When I run the script I get the error for every  DL

The operation couldn't be performed because object 'DLname' couldn't be found on
'DM5PR16A006DC05.NAMPR16A006.PROD.OUTLOOK.COM'.
    + CategoryInfo          : NotSpecified: (:) [Add-DistributionGroupMember], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : [Server=BLUPR16MB0450,RequestId=d469672d-4b76-4ddd-a9fc-d460fdb6437f,TimeStamp=10/14/20
   18 10:21:10 PM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 693292D4,Microsoft.Exchange.Management
  .RecipientTasks.AddDistributionGroupMember
    + PSComputerName        : outlook.office365.com
Did you run the scropt to xreate the dls?

Import-Csv 'c:\temp\o365grps.csv' |  %{New-DistributionGroup -Name $_.Name  -DisplayName $_.DisplayName -Alias $_.Alias -PrimarySmtpAddress $_.PrimarySMTPAddress -ManagedBy $_.managedby}
I have all the distribution lists created as csv files. That worked. The only think left is importing them
from your O365grps.csv run the above command to create the dls in O365
I get this error for every DL

Couldn't find object
"Microsoft.Exchange.Data.Directory.ADMultiValuedProperty`1[Microsoft.Exchange.Data.Directory.ADObjectId]". Please
make sure that it was spelled correctly or specify a different object.
    + CategoryInfo          : NotSpecified: (:) [], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : [Server=BLUPR16MB0450,RequestId=ab8e0221-f26e-4ac3-bc06-6cfe23c98234,TimeStamp=10/15/20
   18 11:31:39 AM] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 289573BB
    + PSComputerName        : outlook.office365.com
please paste the entire command you are using
Import-Csv 'D:\temp\DL\o365grps.csv' |  %{New-DistributionGroup -Name $_.Name  -DisplayName $_
.DisplayName -Alias $_.Alias -PrimarySmtpAddress $_.PrimarySMTPAddress -ManagedBy $_.managedby}
Under the column managedby in your .csv are there any entries?  if not take it off the command.  That may be giving us the error.

Import-Csv 'D:\temp\DL\o365grps.csv' |  %{New-DistributionGroup -Name $_.Name  -DisplayName $_
.DisplayName -Alias $_.Alias -PrimarySmtpAddress $_.PrimarySMTPAddress}
That created the distribution lists however there are no members. Any chance that will take a bit of time to update in Office 365?
ASKER CERTIFIED SOLUTION
Avatar of FOX
FOX
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did it. Thanks so much for sticking with this. I now have DL in Office 365 with all the users
Good work AJ!!!
How many groups were done?
I had 38 groups that were uploaded
Nice!!!