question

EduardoGentaMatias avatar image
0 Votes"
EduardoGentaMatias asked saldana-msft edited

Update birthday and employeeHireDate using microsoft-graph powershell


I need your help to update the user's birthday and emplyeeHireDate in azure ad using microsoft graph by powershell.

I read the articles:
https://docs.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=powershell
https://docs.microsoft.com/en-us/powershell/module/az.resources/update-azaduser?view=azps-7.5.0

But I didn't quite understand how to do it.

microsoft-graph-sdkmicrosoft-graph-identity
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EduardoGentaMatias avatar image
0 Votes"
EduardoGentaMatias answered

I used this code:

Import-Module Microsoft.Graph.Users


$params = @{
Birthday = "1980-09-22"
}

Update-MgUser -UserId $userId -BodyParameter $params

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JanardhanaVedham-MSFT avatar image
0 Votes"
JanardhanaVedham-MSFT answered JanardhanaVedham-MSFT edited

Hi @EduardoGentaMatias-0078 ,

You try using the below power shell SDK code to update Birthday or "employeeHireDate".

 Import-Module Microsoft.Graph.Users
    
 $params = @{
  Birthday = [System.DateTime]::Parse("1982-12-26")
 }
    
 Update-MgUser -UserId $userId -BodyParameter $params

Note : Please replace "BirthDay" with "EmployeeHireDate" in the above powershell SDK code to update emplyeeHireDate user property as well.

Example :

Successful update response in Graph Explorer

198206-image.png

Get "BirthDay" with "EmployeeHireDate" user properties data after the update :

198179-image.png


Hope this helps.

If the answer is helpful to you, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".



image.png (50.3 KiB)
image.png (43.2 KiB)
image.png (43.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EduardoGentaMatias avatar image
0 Votes"
EduardoGentaMatias answered JanardhanaVedham-MSFT edited

Hi @JanardhanaVedham-MSFT,

Execute same commands, but received
Not Found - 404 - 222ms

198385-image.png


and use Get-MgUser -UserId egmatias@xxx.yyyanini.com | fl
198339-image.png


no



image.png (99.0 KiB)
image.png (56.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @EduardoGentaMatias ,

Thanks for your response. Not Found - 404 error because the signed user account is from differnt tenant and hence the user seems not identified or not found . Please try to login to graph explorer app from the same tenant using admin account who have permissions to update user properties in the same tenant. Example : as per the screenshot you are shared, you are trying to update user : egmatias@latam.stefanini.com and hence plese try login from tenant with admin account (i.e., example: user@latam.stefanini.com ).


198458-image.png


Hope this helps.

Since the original question on updating "Birthday" or "employeeHireDate" using PowerShell SDK has been answered and if it is helpful to you, can you please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment". You can always ask a new question as part of new post in this Q&A forum. Thanks for your understanding.


0 Votes 0 ·
image.png (35.9 KiB)
EduardoGentaMatias avatar image
0 Votes"
EduardoGentaMatias answered JanardhanaVedham-MSFT commented

the same error:
198577-image.png



image.png (110.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @EduardoGentaMatias ,

Thanks for your response. I belive that you may be using incorrect userPrinicipalName(UPN) in the API and hence you might be getting 404 - not found error. To know userPrinicipalName(UPN), you can use /me end point to get self user profile and /users end point for all users in your M365 tenant.

You can use /me endpoint to know your userPrinicipalName(UPN) and user ID as shown :

 GET https://graph.microsoft.com/v1.0/me

198791-image.png

To know userPrinicipalName(UPN), you can use /users end point in your M365 tenant.

 GET https://graph.microsoft.com/v1.0/users

Once you identified userPrinicipalName(UPN) , you can use below end points to update the required user properties as explained in above answers. and please make sure to consent required permissions under "Modify permissions" sections in Graph Explorer app and also note that you should have required admin permissions to update other user's properties.

 PATCH https://graph.microsoft.com/v1.0/me
 PATCH https://graph.microsoft.com/v1.0/users/{userPrinicipalName} or {User-ID}

Hope this helps.

As the above provided answer is helpful to you, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".

0 Votes 0 ·
image.png (51.6 KiB)

Hi @EduardoGentaMatias ,

Can you please provide us an update on this?.

If the above proided answer is helpful to you, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".


0 Votes 0 ·
JanardhanaVedham-MSFT avatar image
0 Votes"
JanardhanaVedham-MSFT answered

Hi @EduardoGentaMatias ,

I have also try replicating it at my end. As you can see below, we typically get this error if user not found in our M365 tenant. As you can see in the below example , jvedham1@O365XXXX.onmicrosoft.com does not exit or belongs to my M365 tenant and hence I am getting this 404 - not found error.

Example:

198702-image.png

I would advise you to the below steps :

  1. You can use /me endpoint to know your userPrinicipalName(UPN) and user ID as shown below and Make sure to consent required permissions under "Modify permissions" sections in Graph Explorer app.

    GET https://graph.microsoft.com/v1.0/me

198686-image.png

2.Once you know the UPN from the above step, you can simply execute to update "Birthday" or "employeeHireDate" of your own user profile using /me endpoint. Change the HTTP method to "PATCH" as shown below. Make sure to consent required permissions under "Modify permissions" sections in Graph Explorer app.

 PATCH https://graph.microsoft.com/v1.0/me

198704-image.png

3.You can get all the users of your M365 tenant using the below endpoint and know the userPrinicipalName(UPN) or user IDs of your tenant users. Make sure to consent required permissions under "Modify permissions" sections in Graph Explorer app.

  GET https://graph.microsoft.com/v1.0/users

4.If you are admin user with required permissions in your tenant then you should be able to update other user properties using the below end point. Make sure to consent required permissions under "Modify permissions" sections in Graph Explorer app.

  PATCH https://graph.microsoft.com/v1.0/users/{userPrinicipalName} or {User-ID}

Example :
PATCH https://graph.microsoft.com/v1.0/users/jvedham@0365XXXX.onmicrosoft.com (OR)
PATCH https://graph.microsoft.com/v1.0/users/4abcd677-051a-4c61-8e09-3a05c12345a8

Note: You can always check the API reponse or any corresponding error message in "Response peview" section (as shown below) :
198751-image.png

Hope this helps.

As the original question on updating "Birthday" or "employeeHireDate" using PowerShell SDK is answered and if it is helpful to you, can you please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment". You can always post a new question as part of new post in this Q&A forum and we will provide you required support on the same. Thanks for your understanding.




image.png (77.9 KiB)
image.png (55.4 KiB)
image.png (36.2 KiB)
image.png (19.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EduardoGentaMatias avatar image
0 Votes"
EduardoGentaMatias answered

I received this message in powershell :

199415-image.png



image.png (27.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EduardoGentaMatias avatar image
0 Votes"
EduardoGentaMatias answered JanardhanaVedham-MSFT commented

I used this code:

Import-Module Microsoft.Graph.Users

Connect-MgGraph

$userId = "58ba1b0e-a8be-486b-be00-b697cfbda111"

$params = @{
"Birthday" = [System.DateTime]::Parse("1985-12-15")
"EmployeeHireDate" = [System.DateTime]::Parse("2015-12-11")
}

A UPN can also be used as -UserId.

Update-MgUser -UserId $userId -BodyParameter $params

A UPN can also be used as -UserId.

Get-MgUser -UserId $userId

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Getting the same above error:
199791-image.png


0 Votes 0 ·
image.png (22.6 KiB)
JanardhanaVedham-MSFT avatar image JanardhanaVedham-MSFT MohammedMehtabSiddiqueMINDTREELIMI-9821 ·

Hi @EduardoGentaMatias,

Can you please try it in Graph Explorer APP as per my above answer that I have provided above and let me know the findings.

0 Votes 0 ·