-
Notifications
You must be signed in to change notification settings - Fork 217
Description
Describe the bug
In our automation and unattended scripts, we sometimes retrieve mailbox settings. Using Get-MgUser with the property MailboxSettings returns a STOP error if no mailbox exists. This mimics the behavior of Get-MgUserMailboxSetting.
writeErrorStream : True
Exception : System.Exception: [MailboxNotEnabledForRESTAPI] : The mailbox is either inactive,
soft-deleted, or is hosted on-premise.
TargetObject : { UserId = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, Property = System.String[], ExpandProperty =
, Headers = }
CategoryInfo : InvalidOperation: ({ UserId = xxxx... , Headers = }:<>f__AnonymousType15`4) [Get-MgUser_Get],
Exception
FullyQualifiedErrorId : MailboxNotEnabledForRESTAPI,Microsoft.Graph.PowerShell.Cmdlets.GetMgUser_Get
ErrorDetails : The mailbox is either inactive, soft-deleted, or is hosted on-premise.
Status: 404 (NotFound)
ErrorCode: MailboxNotEnabledForRESTAPI
Date: 2026-02-13T00:00:00
Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
client-request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"xxxx
xx","Slice":"E","Ring":"4","ScaleUnit":"006","RoleInstance":"xxxxxxxxxxxxxxx"}}
Cache-Control : private
Date : Fri, 13 Feb 2026 00:00:00 GMT
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Get-MgUser<Process>, C:\Users\xxxxxxxxxxxxxxxx\xxxxxxxxxxxxxxxxxxxxxxxx\Documents\WindowsPow
erShell\Modules\Microsoft.Graph.Users\2.35.1\exports\ProxyCmdletDefinitions.ps1: line 24736
at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
PSMessageDetails :
Expected behavior
Instead of a STOP error, I prefer Get-MgUser return a null for MailboxSettings if no mailbox exists, similar to the Manager property. Doing this removes the need for a separate call to Get-MgUserMailboxSetting or more complicated error handling (separate try/catch statements for retrieval and processing).
How to reproduce
For an account with no mailbox:
Get-MgUser -UserId <id> -Property MailboxSettings
SDK Version
2.35.1
Latest version known to work for scenario above?
Unknown if previously behaved differently
Known Workarounds
Call both Get-MgUser (without MailboxSettings) and Get-MgUserMailboxSetting.
Debug output
Click to expand log
```DEBUG: [CmdletBeginProcessing]: - Get-MgUser begin processing with parameterSet 'Get'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', TokenCredentialType: 'ClientCertificate', ContextScope: 'Process',
AppName: 'Messaging Team PowerShell Permissions'.
DEBUG: [Authentication]: - Scopes: [Place.Read.All, UserAuthenticationMethod.Read.All, Mail.ReadWrite,
User.RevokeSessions.All, User-Mail.ReadWrite.All, User.ReadWrite.All, UserAuthenticationMethod.ReadWrite.All,
Directory.ReadWrite.All, AuditLogsQuery.Read.All, PeopleSettings.ReadWrite.All, Group.ReadWrite.All,
User.EnableDisableAccount.All, Directory.Read.All, MailboxFolder.ReadWrite.All, User-PasswordProfile.ReadWrite.All,
Calendars.ReadWrite, LicenseAssignment.ReadWrite.All, MailboxSettings.ReadWrite, GroupMember.ReadWrite.All,
AuditLog.Read.All, Policy.Read.All, Reports.Read.All].
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://graph.microsoft.com/v1.0/users/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx?$select=MailboxSettings
Headers:
FeatureFlag : 00000003
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.26200;
en-US),PowerShell/5.1.26100.7705
SdkVersion : graph-powershell/2.35.1
client-request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
NotFound
Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
client-request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"xxxx
xx","Slice":"E","Ring":"4","ScaleUnit":"008","RoleInstance":"xxxxxxxxxxxxxxx"}}
Cache-Control : private
Date : Fri, 13 Feb 2026 00:00:00 GMT
Body:
{
"error": {
"code": "MailboxNotEnabledForRESTAPI",
"message": "The mailbox is either inactive, soft-deleted, or is hosted on-premise.",
"innerError": {
"date": "2026-02-13T00:00:00",
"request-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"client-request-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
}
}
The mailbox is either inactive, soft-deleted, or is hosted on-premise.
Status: 404 (NotFound)
ErrorCode: MailboxNotEnabledForRESTAPI
Date: 2026-02-13T00:00:00
Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
client-request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"xxxx
xx","Slice":"E","Ring":"4","ScaleUnit":"008","RoleInstance":"xxxxxxxxxxxxxxx"}}
Cache-Control : private
Date : Fri, 13 Feb 2026 00:00:00 GMT
Get-MgUser : The mailbox is either inactive, soft-deleted, or is hosted on-premise.
Status: 404 (NotFound)
ErrorCode: MailboxNotEnabledForRESTAPI
Date: 2026-02-13T00:00:00
Headers:
Transfer-Encoding : chunked
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
client-request-id : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"xxxx
xx","Slice":"E","Ring":"4","ScaleUnit":"008","RoleInstance":"xxxxxxxxxxxxxxx"}}
Cache-Control : private
Date : Fri, 13 Feb 2026 00:00:00 GMT
At line:1 char:1
+ Get-MgUser -UserId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -Property Mai ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ UserId = xxxx... , Headers = }:<>f__AnonymousType15`4) [Get-MgUser
_Get], Exception
+ FullyQualifiedErrorId : MailboxNotEnabledForRESTAPI,Microsoft.Graph.PowerShell.Cmdlets.GetMgUser_Get
DEBUG: [CmdletEndProcessing]: - Get-MgUser end processing.
</details>
### Configuration
Name Value
PSVersion 5.1.26100.7705
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.7705
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Windows 11
x64
### Other information
_No response_