Hi @Vijay Ukalkar , unfortunately, as you mentioned, there is no direct way to get the last modified date of a user's profile photo from Azure AD or PowerShell. However, there might be a workaround that you can try.
One possible solution is to use SharePoint Online to store the user's profile photos instead of Azure Blob Storage. SharePoint Online stores the user's profile photo as a file, and you can use SharePoint Online PowerShell cmdlets to get the last modified date of the file. Here's an example of how you can modify your script to use SharePoint Online:
Import the SharePoint Online PowerShell module:
Import-Module Microsoft.Online.SharePoint.PowerShell
Connect to SharePoint Online:
Connect-SPOService -Url https://yourtenant-admin.sharepoint.com
Get the user's profile photo from SharePoint Online:
$photoUrl = "https://yourtenant-my.sharepoint.com/User%20Photos/Profile%20Pictures/$($user.UserPrincipalName)_MThumb.jpg"
$photoFile = Join-Path -Path $env:TEMP -ChildPath $photoFileName
Invoke-WebRequest -Uri $photoUrl -OutFile $photoFile
Get the last modified date of the file:
$photoItem = Get-SPOFile -Url "/User Photos/Profile Pictures/$($user.UserPrincipalName)_MThumb.jpg"
$lastModifiedDate = $photoItem.TimeLastModified
Check if the file has been modified within the last 24 hours:
$lastModifiedDateTime = [DateTime]::Parse($lastModifiedDate)
$timeSpan = New-TimeSpan -Start $lastModifiedDateTime -End (Get-Date)
if ($timeSpan.TotalHours -lt 24) {
# Upload the photo to Azure Blob Storage
Write-Host "Uploading photo for $($user.UserPrincipalName)..."
Set-AzStorageBlobContent -Container $containerName -Blob $photoFileName -File $photoFile -Context $storageContext -Force
Write-Host "Photo for $($user.UserPrincipalName) uploaded successfully."
} else {
Write-Host "No photo found for $($user.UserPrincipalName) or the photo was not modified within the last 24 hours."
}
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James