Exchange Eksport Danych / Exchange Data Export

Podstawową, najłatwiejszą i najszybszą metodą migracji Microsoft Exchange do Office 365 jest uruchomienie tzw. Hybrydowej instalacji. Czasami się jednak zdarza, iż nie możemy tego zrobić. Pozostaje nam zebrać konfiguracje Exchange, a przede wszystkim:

  • wszystkie mailboxy (UserMailbox );
  • wszystkie skrzynki współdzielone (SharedMailbox, GroupMailbox);
  • skrzynki reprezentujące sale i wyposażenie (RoomMailbox, EquipmentMailbox).

Dane, które powinniśmy zawrzeć, oprócz dostępów i ich rodzajów to adresy SMTP.

Do powyższego może nam się przydać  eksport wszystkich grup Active Directory wraz z ich członkami.

Poniżej skrypt to realizujący:

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath SharedMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath SharedMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath SharedMailboxSMTP.txt -Width 5400

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails GroupMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath GroupMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath GroupMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails GroupMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath GroupMailboxSMTP.txt -Width 5400

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath RoomMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath RoomMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath RoomMailboxSMTP.txt -Width 5400

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails EquipmentMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath EquipmentMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath EquipmentMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails EquipmentMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath EquipmentMailboxSMTP.txt -Width 5400

 

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize:Unlimited|Select Identity,Alias,DisplayName,SamAccountName,UserPrincipalName,PrimarySmtpAddress,Name,DistinguishedName,EmailAddresses|ft|Out-File -FilePath Mailbox.txt -Width 5400
Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath MailboxSMTPAddresses.txt -Width 5400
Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize:Unlimited|Select Alias,EmailAddresses|ft|Out-File -FilePath MailboxSMTP.txt -Width 5400

 

$CSVFile = “AD_Groups.csv”
$CSVOutput = @()
$ADGroups = Get-ADGroup -Filter *
$i=0
$tot = $ADGroups.count
foreach ($ADGroup in $ADGroups) {
$i++
$status = “{0:N0}” -f ($i / $tot * 100)
Write-Progress -Activity “Exporting AD Groups” -status “Processing Group $i of $tot : $status% Completed” -PercentComplete ($i / $tot * 100)

$Members = “”

$MembersArr = Get-ADGroup -filter {Name -eq $ADGroup.Name} | Get-ADGroupMember | select Name, objectClass, distinguishedName
if ($MembersArr) {
foreach ($Member in $MembersArr) {
if ($Member.objectClass -eq “user”) {
$MemDN = $Member.distinguishedName
$UserObj = Get-ADUser -filter {DistinguishedName -eq $MemDN}
if ($UserObj.Enabled -eq $False) {
continue
}
}
$Members = $Members + “,” + $Member.Name
}
if ($Members) {
$Members = $Members.Substring(1,($Members.Length) -1)
}
}

$HashTab = $NULL
$HashTab = [ordered]@{
“Name” = $ADGroup.Name
“Category” = $ADGroup.GroupCategory
“Scope” = $ADGroup.GroupScope
“Members” = $Members
}

$CSVOutput += New-Object PSObject -Property $HashTab
}

$CSVOutput | Sort-Object Name | Export-Csv $CSVFile -NoTypeInformation

 

The basic, easiest and fastest way to migrate Microsoft Exchange to Office 365 is to run the so-called Hybrid installation. Sometimes, however, it happens that we can not do it. We have to collect Exchange configurations:

  • all mailboxes (UserMailbox);
  • all shared boxes (SharedMailbox, GroupMailbox);
  • boxes representing rooms and equipment (RoomMailbox, EquipmentMailbox).

The data to be included, in addition to access and their types, are SMTP addresses.

Exporting all Active Directory groups together with their members may be useful for the above.

The script:

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath SharedMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath SharedMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath SharedMailboxSMTP.txt -Width 5400

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails GroupMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath GroupMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath GroupMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails GroupMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath GroupMailboxSMTP.txt -Width 5400

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath RoomMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath RoomMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath RoomMailboxSMTP.txt -Width 5400

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails EquipmentMailbox -ResultSize:Unlimited | Select Identity,Alias,DisplayName,UserPrincipalName,EmailAddresses,PrimarySmtpAddress,Name,DistinguishedName | sort displayname
$Mailboxes |ft|Out-File -FilePath EquipmentMailbox.txt -Width 5400
$mailboxes | sort displayname | foreach {Get-MailboxPermission -Identity $_.alias | ft identity,user,accessrights}|Out-File -FilePath EquipmentMailboxPermission.txt -Width 5400
Get-Mailbox -RecipientTypeDetails EquipmentMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath EquipmentMailboxSMTP.txt -Width 5400

 

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize:Unlimited|Select Identity,Alias,DisplayName,SamAccountName,UserPrincipalName,PrimarySmtpAddress,Name,DistinguishedName,EmailAddresses|ft|Out-File -FilePath Mailbox.txt -Width 5400
Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize:Unlimited |Select-Object displayname -expandproperty emailaddresses| Select DisplayName,SmtpAddress | sort displayname| Out-File -FilePath MailboxSMTPAddresses.txt -Width 5400
Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize:Unlimited|Select Alias,EmailAddresses|ft|Out-File -FilePath MailboxSMTP.txt -Width 5400

 

$CSVFile = “AD_Groups.csv”
$CSVOutput = @()
$ADGroups = Get-ADGroup -Filter *
$i=0
$tot = $ADGroups.count
foreach ($ADGroup in $ADGroups) {
$i++
$status = “{0:N0}” -f ($i / $tot * 100)
Write-Progress -Activity “Exporting AD Groups” -status “Processing Group $i of $tot : $status% Completed” -PercentComplete ($i / $tot * 100)

$Members = “”

$MembersArr = Get-ADGroup -filter {Name -eq $ADGroup.Name} | Get-ADGroupMember | select Name, objectClass, distinguishedName
if ($MembersArr) {
foreach ($Member in $MembersArr) {
if ($Member.objectClass -eq “user”) {
$MemDN = $Member.distinguishedName
$UserObj = Get-ADUser -filter {DistinguishedName -eq $MemDN}
if ($UserObj.Enabled -eq $False) {
continue
}
}
$Members = $Members + “,” + $Member.Name
}
if ($Members) {
$Members = $Members.Substring(1,($Members.Length) -1)
}
}

$HashTab = $NULL
$HashTab = [ordered]@{
“Name” = $ADGroup.Name
“Category” = $ADGroup.GroupCategory
“Scope” = $ADGroup.GroupScope
“Members” = $Members
}

$CSVOutput += New-Object PSObject -Property $HashTab
}

$CSVOutput | Sort-Object Name | Export-Csv $CSVFile -NoTypeInformation

 

Group script: https://gallery.technet.microsoft.com/scriptcenter/Export-all-AD-groups-and-3ae6fb42