Sharing two Powershell Spells which we have used in one of the acquisition.
We have a requirement to create contacts and forward the emails to the other company.
Here is what will be done on a high level:
- First Script will connect exchange onpremise –> create the contacts and hide these in GAL.
- Wait for Azure Ad connect sync the updates
- Run the second script to add forwarding to the created contacts.
Step first is to create the CSV file as below:
Download the solution zip from below and extract it.
Update the BulkMailContactCreation.ps1 script
1. Line 113 –> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeserver.labtest.com/PowerShell/ -Authentication Kerberos
update onpremise exchnage server fqdn to which it can connect to import exchnage shell.
2. Line 135 –> $name = “LABtest-” + $extsplit +”-fwd“
update the prefix you want for contacts as contacts will be created with name labtest-test1-fwd following this naming convention.
you can add your company specific code.
3. Line 139 –> new-mailcontact -Name $name -ExternalEmailAddress $externaladdress -OrganizationalUnit “labtest.com/Exchange/Contacts”
Update the Organizational unit in which these contacts will be created.
Now you can run the script from the working location.
Enter csv file name –> example : sample.csv
It will start creating the mail contacts and will also set them as hidden.
If you do not want them hidden in GAL then comment the line 158
set-mailcontact -id $name -HiddenFromAddressListsEnabled:$true
Now we have to wait for azure ad connect synchronization to finish so that we can add forwarding to these newly created contacts
Run the Script BulkMailForward.ps1, it will ask for CSV file name same as other script.
This script will also ask for crdentials to connect to exchange online to perform the forwarding operation.
This solution spell will definitely assist you in the scenarios like above.
Thanks for reading and downloading