Getting Bed request when converting user mailbox into shared using Powershell

Abhishek Goyal 246 Reputation points
2023-05-02T12:12:08.97+00:00

I was trying to convert user mailbox into shared mailbox using powershell command

Set-Mailbox -Identity "example@example.com" -Type Shared

But got the error:

write-Error: {"error":{"code":"BadRequest","message":"Cmdlet needs proxy. Current Server FQDN : DM8PR22MB2759.namprd22.prod.outlook.com,
Required Server FQDN : DS0PR22MB4123.namprd22.prod.outlook.com","innererror":{"message":"Cmdlet needs proxy. Current Server FQDN
: DM8PR22MB2759.namprd22.prod.outlook.com, Required Server FQDN :
DS0PR22MB4123.namprd22.prod.outlook.com","type":"Microsoft.Exchange.Admin.OData.Core.ODataServiceException","stacktrace":"   at
Microsoft.Exchange.AdminApi.CommandInvocation.CommandInvocation.InvokeCommand(QueryContext queryContext, CmdletInvokeInputType
cmdletInvokeInputType)\r\n   at
Microsoft.Exchange.Admin.OData.Core.PathSegmentToExpressionTranslator.Translate(OperationImportSegment segment)\r\n   at
Microsoft.Exchange.Admin.OData.Core.QueryContext.ResolveQuery(ODataContext context, Int32 level)\r\n   at
Microsoft.Exchange.Admin.OData.Core.Handlers.OperationHandler.Process(IODataRequestMessage requestMessage, IODataResponseMessage
responseMessage)\r\n   at Microsoft.Exchange.Admin.OData.Core.Handlers.RequestHandler.Process(Stream requestStream)"}}}

I used ExchangeOnlineManagement Module. For making connection with exchange online I used a azure App with permission Exchange.Manage(Delegated) and login using the user who are Exchange Administrator.

I think my permissions are correct. Please help me out for same.

Appreciate your efforts.

Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,175 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dmitry Lobkov 20 Reputation points
    2023-06-08T21:21:00.98+00:00

    I believe EXO doesn't handle anchor header properly when dealing with 'Exchange.Manage' tokens. EXO PS uses a default anchor in UPN format, while some commands like 'Set-Mailbox -Type' do not work with it. For sure it's a backend routing issue, but it's possible to override the header and make some particular commands work.

    The piece of code worked for me with the latest EXO V3:

    $lastConnect = (Get-ConnectionInformation)[-1]
    $ctx = [Microsoft.Exchange.Management.ExoPowershellSnapin.ConnectionContextFactory]::GetAllConnectionContexts() | ? { $_.ConnectionId -eq $lastConnect.ConnectionId}
    Write-Host "Default anchor:  $($ctx.RoutingHintPrefix):$($ctx.RoutingHint)" 
    $mbx = Get-Mailbox -Identity 'example@example.com'
    $ctx.RoutingHintPrefix = "MBX"
    $ctx.RoutingHint = "$($mbx.ExchangeGuid)@$($lastConnect.TenantID)"
    Set-Mailbox -Identity 'example@example.com' -Type Shared
    
    4 people found this answer helpful.

  2. Vasil Michev 95,341 Reputation points MVP
    2023-05-02T16:23:35.9+00:00

    Try logging in directly with the user, using Connect-ExchangeOnline. If the same issue occurs, best open a support case. If the cmdlet works OK, the issue is likely with the way you handle authentication.