Mailbox Syntax

Rising Flight 5,216 Reputation points
2022-12-30T21:46:00.877+00:00

Hi All

I am using exchange 2016 Hybrid Environment. I want to create a shared mailbox and regular mailbox from PowerShell in exchange onprem and after a week i may migrate to exchange online.

is the below syntax correct to create shared mailbox and regular mailbox in Exchange Onprem.
Please correct me with the below syntaxes(I want to give SamAccountName since in some cases it can be more than 20 characters)

RegularMailbox  
New-Mailbox -Name "Test RegularMBX" -Firstname "Test" -LastName "RegularMBX" -UserPrincipalName "******@contoso.com" -SamAccountName "******@contoso.com" -OnPremisesOrganizationalUnit "OU=Regular,OU=Mailboxes,DC=contoso,DC=com"  
  
SharedMailbox  
New-Mailbox -Shared -Name "Test SharedMBX" -Firstname "Test" -LastName "SharedMBX" -UserPrincipalName "******@contoso.com" -SamAccountName "******@contoso.com" -OnPremisesOrganizationalUnit "OU=Shared,OU=Mailboxes,DC=contoso,DC=com"  
Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,178 questions
Exchange | Exchange Server | Management
Exchange | Hybrid management
0 comments No comments
{count} votes

Accepted answer
  1. Aholic Liang-MSFT 13,886 Reputation points Microsoft External Staff
    2023-01-03T07:41:59.13+00:00

    Hi @Rising Flight ,
    For password parameters, please refer to the following syntax:

    -Password (ConvertTo-SecureString -String 'P@ssw0rd' -AsPlainText -Force)  
    

    275577-2023-1-3-2.png
    In addition, please confirm that distinguishedName of specify organizational unit in ADUC. In my environment, it is displayed as "CN=XX, DC=contoso, DC=com".


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Aholic Liang-MSFT 13,886 Reputation points Microsoft External Staff
    2023-01-02T07:25:19.807+00:00

    Hi @Rising Flight ,
    According to my test, there is two error in original command line,please refer to the following command to create the user mailbox:

    New-Mailbox -Name "Test RegularMBX" -Firstname "Test" -LastName "RegularMBX" -UserPrincipalName "******@contoso.com" -SamAccountName "Test.RegularMBX" -OrganizationalUnit "CN=Users,DC=contoso,DC=com"  
    

    275260-2023-1-2-3.png

    Similarly, you could follow the command below to create a shared mailbox and add access permissions:

    New-Mailbox -Shared -Name " Test SharedMBX " -DisplayName " Test SharedMBX " -Alias “TestSharedMBX”  -SamAccountName "Test.RegularMBX" -OrganizationalUnit " CN=Users,DC=contoso,DC=com”  | Add-MailboxPermission -User “admin” -AccessRights FullAccess -InheritanceType All  
    

    (Kindly note:You could open ADUC to see the distinguishedName for the organizational unit that you want to specify.)


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Rising Flight 5,216 Reputation points
    2023-01-03T04:50:38.53+00:00

    Thanks alot, when i put password in the syntax i am getting error

    New-Mailbox -Name "Test RegularMBX" -Firstname "Test" -LastName "RegularMBX" -UserPrincipalName "Test.RegularMBX@Company portal .com" -SamAccountName "Test.RegularMBX" -Password 'P@ssw0rd' -OrganizationalUnit "OU=Regular,OU=Mailboxes,DC=contoso,DC=com"

    Cannot process argument transformation on parameter 'Password'. Cannot convert the "P@ssw0rd" value of type "System.String" to type "System.Security.SecureString".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.