forked from Moopus1/365-Cross-Tenant-Migration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DestinationUserCreation.ps1
41 lines (32 loc) · 1.91 KB
/
DestinationUserCreation.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<#
.DESCRIPTION
Run this script in the destination PowerShell environment.
This script creates the respective MailUsers in the destination location. It will create them with needed fields: DisplayName, ExternalEmailAddresses
(this is their source email), MicrosoftOnlineServicesID (this is their destination UPN / email), and lastly the mail users Password. By default, I've
simply mapped them to all be Apples123!. You can change it below.
After creating the MailUser, it will match the source ExchangeGuid, source ArchiveGuid, and add the original LegacyExchageDN as X500 proxy, and any
additional X500 addresses.
The source CSV exported report from CrossTenantMigration-Report.ps1 .
.NOTES
Name: DestinationUserCreation.ps1
Author: Alex - [email protected]
Version: 1.0
DateCreated: JUL 2022
#>
$CSV = Import-Csv -Path C:\temp\Export.csv
Write-Host "Creating mail users!"
$CSV | ForEach-Object {
# Creation of user below --------------------------------------------------------------------------------
$trunk = "x500:"+$_.LegacyExchangeDN
$AdditionalX500 = $_.AdditionalX500
$Secure = ConvertTo-SecureString "Apples123!" -AsPlainText -Force
New-MailUser -Name $_.DisplayName -ExternalEmailAddress $_.PrimarySmtp -MicrosoftOnlineServicesID $_.DestinationSmtp -Password $Secure
Write-Host "Waiting..." -ForegroundColor Green
Start-Sleep -Seconds 2
# Setting of values below ---------------------------------------------------------------------------------
Write-Host "Setting new user's values!" -ForegroundColor Green
Set-MailUser -Identity $_.DisplayName -ExchangeGuid $_.ExchangeGuid -ArchiveGuid $_.ArchiveGuid -EmailAddresses @{add=$trunk}
Start-Sleep -Seconds 1
#Add Additional X500 Addresses
Set-MailUser -Identity $_.DisplayName -EmailAddresses @{add=$AdditionalX500} -ErrorAction SilentlyContinue
}