MSGraph-SDK-Code-Generator icon indicating copy to clipboard operation
MSGraph-SDK-Code-Generator copied to clipboard

New-MgUser fails 'does not exist or one of its queried reference-property objects are not present.'

Open ThePoShWolf opened this issue 5 years ago • 1 comments

When creating a new user with New-MgUser, if not all of the required parameters are passed it throws a rather cryptic error:

Resource 'User_<guid>' does not exist or one of its queried reference-property objects are not present.

I found that this happened because I wasn't passing a MailNickname parameter. After also passing that parameter, it created the user as expected.

For anyone else that runs into this, here are the required parameters.

It would be great if the module returned a better error or had required parameters so it was clear in the cmdlet's help. I'm sure this has or will come up in other cmdlets. AB#7085

ThePoShWolf avatar May 18 '20 16:05 ThePoShWolf

Thank you for bringing this up. This error message is a pass-through from the service. We'd like to capture this information for future work. This is actually a service feature request that would then require generation support.

We will need to:

  • [ ] define insertrequirement term to specify which properties are required when inserting.
  • [ ] updates to metadata to specify required default properties.
  • [ ] generators updated to pickup these custom annotations.

MIchaelMainer avatar May 21 '20 20:05 MIchaelMainer

@peombwa this is an older issue for PowerShell. Can you review it when you have a couple of minutes and either close it or transfer it to the PS repo please?

baywet avatar Nov 27 '23 14:11 baywet

This is an old service issue that can be closed. The API will now fail with the correct error message, indicating which property is missing. In this case, Property mailNickname value is required but is empty or missing.

The missing requiredProperties annotations mentioned by Michael is currently being tracked at https://github.com/microsoftgraph/msgraph-metadata/issues/278.

peombwa avatar Nov 27 '23 17:11 peombwa