Open
Description
When I used to retrieve user photo data via a REST API call I would be given the photo data as a byte stream which I could get convert to a base64 string for comparison with another system we have that present the user photo as a base64 string.
Here is a snippet of my code that uses the direct REST call:
$body = @{grant_type = "client_credentials"; resource = $resource; client_id = $AzureClientID; client_secret = $AzureClientSecret}
$oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$AzureTenantDomain/oauth2/token?api-version=1.0 -Body $body
$headerParams = @{'Authorization' = "$($oauth.token_type) $($oauth.access_token)"}
[uri]$uriGraphEndpoint = "https://graph.microsoft.com/v1.0/users/$($User.mail)/photo/" + '$value'
try {
$response = Invoke-WebRequest -Method Get $uriGraphEndpoint.AbsoluteUri -Headers $headerParams -ErrorAction SilentlyContinue
try {
$Worker = Get-WDWorker -Credential $WDCredentials -RequestType Photo,Contact -WorkerID $User.EmployeeNumber -Environment $WDEnvironment
if([Convert]::ToBase64String($response.Content) -ne $Worker.ImageData) {
Write-Verbose "Photo for $($User.Name) is different"
$WDResponse = Set-WDWorkerPhoto -Credential $WDCredentials -WorkerID $User.EmployeeNumber -PhotoData ([Convert]::ToBase64String($response.Content)) -Environment $WDEnvironment
if($WDResponse -match '^\S{32}$') {
Write-Verbose "Workday photo for $($User.Name) updated successfully."
} else {
Write-Verbose "Workday photo update for $($User.Name) failed."
}
} else {
Write-Verbose "Photo for $($User.Name) is the same"
}
}
With Get-MgUserPhotoContent as it works today I have to first save the photo as a file before then converting it for comparison and then delete the file, which seems unnecessary.
Is there any possibility of getting this cmdlet updated so that it has something like a -AsByteStream option?