Is it possible to extract and/or set users' birthday with a PowerShell script?
-
20-02-2021 - |
Question
I've been doing some investigating and apparently a user's birthday date (the one that shows up on Delve) is not stored in a property inside the user's own office365 account object.
I'm trying to create a PowerShell script in Azure where I can update a user's birthday with a value that is currently in a SharePoint list. As of right now if I could find out how to even set the birthday property hard-coded, that would be some progress.
Get-MsolUser and Set-Msoluser don't work because as I stated previously the birthday date isn't there for some reason, but I can retrieve a user's birthday utilizing Microsoft Graph and sending a GET request to this URL of the API https://graph.microsoft.com/v1.0/users/{user_id}/birthday
.
The response of that request is what I would like to be able to automatically set, but I can't seem to find a way to do so.
Solution 2
It finally worked. Here's the code to change one single user's birthday date (...where $creds name is the name of a credential created on the azure automation account used to run the script, with full sharepoint admin privileges given on the admin site (the same site used as url)):
Connect-PnPOnline -Url https://xxxx-admin.sharepoint.com/ -Credentials $creds
Set-PnPUserProfileProperty -Account 'xx.xxxx@xxx.com' -PropertyName "SPS-Birthday" -Value "01/14/2020"```
OTHER TIPS
You can set the birth date using Set-PnPUserProfileProperty in PnP PowerShell.
For Example:
Set-PnPUserProfileProperty -Account 'user@tenant.onmicrosoft.com' -PropertyName "SPS-Birthday" -Value "01/14/2020"
Output:
Update from comments:
I tried running the graph query https://graph.microsoft.com/v1.0/users/{user_id}/birthday
. This also returns the same birth date:
Update Birth date using Microsoft Graph:
Method: PATCH
Endpoint:
https://graph.microsoft.com/v1.0/users/{user_id}
Request body:
{
"birthday":"2014-01-01T00:00:00Z"
}