Azure AD Connect > Managing with Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-140001%22%20slang%3D%22en-US%22%3EAzure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140001%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Guys%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20We%20currently%20run%20Azure%20AD%20Connect%20with%20our%202011%20server%20to%20Sync%20with%20Office%20365.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20a%20shared%20mailbox%20that%20somehow%20has%20the%20default%20Microsoft%20email%20address%20as%20the%20primary%20email%20address.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20tried%20many%20powershelgl%20commands%20but%20I%20cant%20seem%20to%20correct%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20someone%20please%20recommend%20the%20MSonline%20module%20command%20to%20set%20the%20primary%20email%20address%20on%20a%20shared%20mailbox%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPrimary%20is%20currently%3A%26nbsp%3Bhelpdesk%40mycompany.onmicrosoft.com%20%26gt%3B%20should%20be%20helpdesk%40mycompany.com%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMany%20Thanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-140001%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-140035%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140035%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20don't%20use%20an%20onsite%20exchange%20server%20any%20more.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20%5B%3CSTRONG%3Esolved%3C%2FSTRONG%3E%5D%20it%20by%20doing%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E**%20-%20REMOVE%20USERS%3A%20%3CSTRONG%3E(caution%20back%20up%20.pst%20offline%20emails%20first)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20Move%20the%20AD%20user%20on%20your%20local%20server%20into%20a%20No%20sync%20folder%3C%2FP%3E%0A%3CP%3E2.%20Sync%20the%20AD%20with%20Start-ADSyncSyncCycle%20-PolicyType%20Delta%3C%2FP%3E%0A%3CP%3E3.%20This%20will%20put%20the%20AD%20user%20on%20Office%20365%20into%20the%20recycling%20bin.%3CBR%20%2F%3E4.%20Get-MsolUser%20-ReturnDeletedUsers%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EThen%20permanantly%20delete%20the%20user%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E5.%20Remove-MsolUser%20%E2%80%93UserPrincipalName%20user%40mycompany.com%26nbsp%3B-RemoveFromRecycleBin%3C%2FP%3E%0A%3CP%3E6.%20Move%20the%20AD%20user%20back%20into%20the%20SYNC%20folder%20and%20force%20a%20sync%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E**%20-%20FORCE%20SYNC%20NOW%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E7.%20Start-ADSyncSyncCycle%20-PolicyType%20Delta%3C%2FP%3E%0A%3CP%3E8.%20Check%20the%20Office%20365%20Portal%20%26gt%3B%20Done.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20for%20your%20assistance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-140034%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140034%22%20slang%3D%22en-US%22%3E%3CP%3EWell%20I%20can%20see%20that%20you%20have%20Exchange%20on-premises.%20What%20primary%20SMTP%20address%20is%20set%20in%20Exchange%3F%20Are%20you%20able%20to%20change%20email%20address%20via%20ECP%3F%3C%2FP%3E%0A%3CP%3EAs%20from%20error%20message%20it%20says%20that%20you%20have%20to%20change%20this%20internaly%2C%20afterwards%20changes%20should%20be%20synced%20to%20cloud%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-140024%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140024%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEven%20using%20the%20Exchange%20Powershell%20I%20get%20an%20error%20but%20it%20is%20being%20synced%20with%20Azure%20AD%20Connect%20(formerly%20Azure%20AD%20Sync)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20%3CSTRONG%3Eattached%3C%2FSTRONG%3E%20a%20%3CSTRONG%3Escreenshot%3C%2FSTRONG%3E%20of%20the%20error.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-140023%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140023%22%20slang%3D%22en-US%22%3E%3CP%3EYes%20you%20are%20correct%2C%20and%20I%20can%20not%20see%20a%20command%20to%20change%20the%20primary%20email%20on%20a%20%3CSTRONG%3Eshared%20mailbox%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20can%20use%26nbsp%3BSet-MsolUserPrincipalName%20but%20it%20only%20changes%20the%20value%20on%20a%20user%20not%20a%20%3CSTRONG%3Eshared%20mailbox%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20I%20use%20the%20Exchange%20cmdlet%20to%20connect%20to%20Office%20365%20and%20use%20other%20commands%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-140022%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140022%22%20slang%3D%22en-US%22%3E%3CP%3Eit's%20because%26nbsp%3B%3CSPAN%3EMsOnline%20powershell%20module%20does%20not%20contain%20Set-Mailbox%20cmdlet.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETo%20view%20all%20the%20available%20cmdlets%20that%20are%20available%20in%20MsOnline%20module%20you%20can%20enter%20in%20powershell%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3Eget-command%20-Module%20msonline%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-140019%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140019%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20reply.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20don't%20think%20the%20Powershell%20for%20AD%20connect%20uses%20that%20cmdlet%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20am%20using%20the%20following%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EImport-Module%20MsOnline%3C%2FLI%3E%0A%3CLI%3EEnter%20Connect-MsolService%20-Credential%20%24credential%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EI%20tried%26nbsp%3B%3CSPAN%20class%3D%22crayon-r%20%22%3ESet%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-cn%22%3E-Mailbox%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22crayon-cn%22%3E-Identity%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22crayon-i%22%3EoldEmail%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E%40%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-i%22%3Edomain%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-i%22%3Ecom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22crayon-cn%22%3E-EmailAddresses%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22crayon-i%22%3EnewEmail%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E%40%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-i%22%3Edomain%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-i%22%3Ecom%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20does%20not%20recognise%20the%20command%20Set-Mailbox.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAny%20ideas%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-140018%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20AD%20Connect%20%26gt%3B%20Managing%20with%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140018%22%20slang%3D%22en-US%22%3E%3CP%3EI%20guess%20you%20have%20to%20use%20Exchange%20online%20cmdlets%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHow%20to%20connect%20to%20Exchange%20online%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fjj984289(v%3Dexchg.160).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fjj984289(v%3Dexchg.160).aspx%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Echange%20mailbox%20address%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.remylarrieu.com%2Fen%2Foffice-365-change-a-shared-mailbox-email-address%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.remylarrieu.com%2Fen%2Foffice-365-change-a-shared-mailbox-email-address%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi Guys,

 

1. We currently run Azure AD Connect with our 2011 server to Sync with Office 365.

 

I have a shared mailbox that somehow has the default Microsoft email address as the primary email address.

 

I have tried many powershelgl commands but I cant seem to correct it.

 

Can someone please recommend the MSonline module command to set the primary email address on a shared mailbox

 

Primary is currently: helpdesk@mycompany.onmicrosoft.com > should be helpdesk@mycompany.com

 

Many Thanks

7 Replies

I guess you have to use Exchange online cmdlets

 

How to connect to Exchange online:

https://technet.microsoft.com/en-us/library/jj984289(v=exchg.160).aspx

 

change mailbox address:

http://www.remylarrieu.com/en/office-365-change-a-shared-mailbox-email-address/

Thanks for the reply.

 

I don't think the Powershell for AD connect uses that cmdlet:

 

I am using the following:

  1. Import-Module MsOnline
  2. Enter Connect-MsolService -Credential $credential

I tried Set-Mailbox -Identity oldEmail@domain.com -EmailAddresses newEmail@domain.com

 

It does not recognise the command Set-Mailbox.

 

Any ideas

 

Thanks

it's because MsOnline powershell module does not contain Set-Mailbox cmdlet.

 

To view all the available cmdlets that are available in MsOnline module you can enter in powershell

get-command -Module msonline

Yes you are correct, and I can not see a command to change the primary email on a shared mailbox

 

I can use Set-MsolUserPrincipalName but it only changes the value on a user not a shared mailbox

 

Can I use the Exchange cmdlet to connect to Office 365 and use other commands?

 

Thanks

Hello,

 

Even using the Exchange Powershell I get an error but it is being synced with Azure AD Connect (formerly Azure AD Sync)

 

I have attached a screenshot of the error.

 

Thanks

Well I can see that you have Exchange on-premises. What primary SMTP address is set in Exchange? Are you able to change email address via ECP?

As from error message it says that you have to change this internaly, afterwards changes should be synced to cloud

We don't use an onsite exchange server any more.

 

I [solved] it by doing the following:

 

** - REMOVE USERS: (caution back up .pst offline emails first)

 

1. Move the AD user on your local server into a No sync folder

2. Sync the AD with Start-ADSyncSyncCycle -PolicyType Delta

3. This will put the AD user on Office 365 into the recycling bin.
4. Get-MsolUser -ReturnDeletedUsers

 

Then permanantly delete the user:


5. Remove-MsolUser –UserPrincipalName user@mycompany.com -RemoveFromRecycleBin

6. Move the AD user back into the SYNC folder and force a sync

 

** - FORCE SYNC NOW

 

7. Start-ADSyncSyncCycle -PolicyType Delta

8. Check the Office 365 Portal > Done.

 

Thanks for your assistance.