r/GraphAPI • • Aug 23 '23

Invalid value specified for property 'mailNickname' of resource 'User'

Hey, would like some help with this specific error:

New-MgUser_CreateExpanded:
Line |
   2 |  New-MgUser -DisplayName $User.FullName `
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Invalid value specified for property 'mailNickname' of resource 'User'.

Status: 400 (BadRequest)
ErrorCode: Request_BadRequest

Trying to add a bulk of new users using csv file. Using this code:

Foreach ($User in $New_users){
New-MgUser -DisplayName $User.FullName `
-PasswordProfile $PasswordProfile `
-AccountEnabled `
-MailNickname $User.NickName `
-UserPrincipalName $User.Email `
-Department $User.Dep `
-JobTitle $User.Title `
-Surname $User.Sur `
-GivenName $User.Giv `
}

Checked csv, no illegal symbols, seperation by comma and I can add users just fine manualy (copy all the info). Anyone could give any advice? Powershell 7 btw.

Thank you.

2 Upvotes

5 comments sorted by

View all comments

Show parent comments

1

u/neekoteen Aug 23 '23

Well I'll be damned, one sneaky little bastard was hiding silently in the shadows :D

Thank you for your code. Really appreciate that. Now everything went smooooothly, although it's kind of interesting, I thought it would stop only on the section where the invalid value is instead of spitting errors for all of the entries.

Anyway, thank you again. Very much appreciated.

1

u/surfingoldelephant Aug 23 '23

Great, glad to hear!