microsoftgraph / microsoftgraph/msgraph-sdk-powershell
Add -AsByteStream option to Get-MgUserPhotoContent
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 898
- Forks
- 230
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 31
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Get-MgUserPhotoContent entry point and inspecting how it currently returns or saves photo content. Compare related cmdlets for response-content handling, then add coverage for the requested byte-stream behavior and verify that photo data can be consumed without a temporary file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- api, cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100