Forum Discussion
SX
Feb 18, 2025Copper Contributor
The term 'New-MailContact' is not recognized
Hi Support,
I am trying to bulk import external contacts to the tenant. I have come across several other Q&As which have the similar issue.
However, the issue is slightly different - I have assigned this test account recipient management role which should be able to create mail recipient and related stuff. This user, eg, test user, is able to do it from the online version from exchange admin center but cant use the cmd to run via powershell. It was working probably a week ago and I haven't changed anything.
It also works fine when authenticating using a global admin account.
Looking forward to your reply.
Thanks in advance,
Sheila
- LainRobertsonSilver Contributor
Hi SX,
You're correct in that under default conditions, New-MailContact should be available for members of the Recipient Management role, however, it would pay to check that holds true for your environment.
Here's a couple of commands you can use to validate which roles permit access to New-MailContact as well as cross-check the RBAC memberships your test account currently holds.
Note the inline comment pertaining to leveraging the -CmdletParameters parameter, as Exchange Online filters beyond the base commandlet and into the actual parameter usage.
# Microsoft Learn reference: # https://learn.microsoft.com/en-us/powershell/exchange/find-exchange-cmdlet-permissions?view=exchange-ps#use-powershell-to-find-the-permissions-required-to-run-a-cmdlet # Use this command to verify which roles can run a given command. It may pay to also add in the -CmdletParameters to get a more granular response from Exchange Online. Get-ManagementRole -Cmdlet "New-MailContact" | ForEach-Object { Get-ManagementRoleAssignment -Role $_.Name -Delegating $false | Select-Object -Property Role, RoleAssigneeType, RoleAssigneeName; } | Format-Table -AutoSize; # Use this command to enumerate the members of all roles, which you can use to cross-check the test account's current role-based access. Get-RoleGroup | ForEach-Object { $Role = $_; Get-RoleGroupMember -Identity $_.Identity | ForEach-Object { [PSCustomObject] @{ Role = $Role.Name; Type = $_.RecipientType; Member = $_.Identity; } } }
Cheers,
Lain
- AP_TC_ECASDCopper Contributor
New-MgContact and New-MgUserContact are cmdlets in Microsoft Graph PowerShell, but they serve different purposes:
- New-MgContact:
- This cmdlet is used to create a new organizational contact in Microsoft 365. Organizational contacts are typically used for external contacts that are not part of the organization but need to be available in the directory for communication purposes1.
- Example usage:New-MgContact -DisplayName "John Doe" -Mail "email address removed for privacy reasons"
- New-MgUserContact:
- This cmdlet is used to create a new personal contact for a specific user in Microsoft 365. Personal contacts are managed by individual users and are not shared across the organization2.
- Example usage:New-MgUserContact -UserId $userId -DisplayName "Jane Smith" -EmailAddresses @{Address="email address removed for privacy reasons"; Name="Jane Smith"}
In summary, New-MgContact is for organizational contacts, while New-MgUserContact is for personal contacts managed by individual users.
- New-MgContact:
The New-Mailcontact cmdlet should be available after running Connect-ExchangeOnlineManagement.
What version of the module are you using? I'm using 3.7.0
- AP_TC_ECASDCopper Contributor
New-MgContact and New-MgUserContact are cmdlets in Microsoft Graph PowerShell, but they serve different purposes:
- New-MgContact:
- This cmdlet is used to create a new organizational contact in Microsoft 365. Organizational contacts are typically used for external contacts that are not part of the organization but need to be available in the directory for communication purposes1.
- Example usage:New-MgContact -DisplayName "John Doe" -Mail "email address removed for privacy reasons"
- New-MgUserContact:
- This cmdlet is used to create a new personal contact for a specific user in Microsoft 365. Personal contacts are managed by individual users and are not shared across the organization2.
- Example usage:New-MgUserContact -UserId $userId -DisplayName "Jane Smith" -EmailAddresses @{Address="email address removed for privacy reasons"; Name="Jane Smith"}
In summary, New-MgContact is for organizational contacts, while New-MgUserContact is for personal contacts managed by individual users.
- New-MgContact: