Skip to content

Commit 0abaa44

Browse files
committed
Fix: enable graph part of standard again, now that
it works via GDAP
1 parent 1efed26 commit 0abaa44

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardProfilePhotos.ps1

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,18 @@ function Invoke-CIPPStandardProfilePhotos {
4242
# true if wanted state is enabled, false if disabled
4343
$DesiredState = $StateValue -eq 'enabled'
4444

45-
<#
46-
HACK This does not work, as the API endpoint is not available via GDAP it seems? It works in the Graph Explorer, but not here.
47-
The error is: "Authorization failed because of missing requirement(s)."
48-
I'm keeping the code here for now, so it's much easier to re-enable if Microsoft makes it possible someday. -Bobby
49-
#>
50-
5145
# Get current Graph policy state
52-
# $Uri = 'https://graph.microsoft.com/beta/admin/people/photoUpdateSettings'
53-
# $CurrentGraphState = New-GraphGetRequest -uri $Uri -tenantid $Tenant
54-
# $UsersCanChangePhotos = if (($CurrentGraphState.allowedRoles -contains 'fe930be7-5e62-47db-91af-98c3a49a38b1' -and $CurrentGraphState.allowedRoles -contains '62e90394-69f5-4237-9190-012177145e10') -or
55-
# $null -ne $CurrentGraphState.allowedRoles) { $false } else { $true }
56-
# $GraphStateCorrect = $UsersCanChangePhotos -eq $DesiredState
57-
46+
$Uri = 'https://graph.microsoft.com/beta/admin/people/photoUpdateSettings'
47+
$CurrentGraphState = New-GraphGetRequest -uri $Uri -tenantid $Tenant
48+
$UsersCanChangePhotos = if (($CurrentGraphState.allowedRoles -contains 'fe930be7-5e62-47db-91af-98c3a49a38b1' -and $CurrentGraphState.allowedRoles -contains '62e90394-69f5-4237-9190-012177145e10') -or
49+
$null -ne $CurrentGraphState.allowedRoles) { $false } else { $true }
50+
$GraphStateCorrect = $UsersCanChangePhotos -eq $DesiredState
5851

5952
# Get current OWA mailbox policy state
6053
$CurrentOWAState = New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OwaMailboxPolicy' -cmdParams @{Identity = 'OwaMailboxPolicy-Default' } -Select 'Identity,SetPhotoEnabled'
6154
$OWAStateCorrect = $CurrentOWAState.SetPhotoEnabled -eq $DesiredState
62-
# $CurrentStatesCorrect = $GraphStateCorrect -eq $true -and $OWAStateCorrect -eq $true
63-
$CurrentStatesCorrect = $OWAStateCorrect -eq $true
55+
56+
$CurrentStatesCorrect = $GraphStateCorrect -eq $true -and $OWAStateCorrect -eq $true
6457

6558
if ($Settings.remediate -eq $true) {
6659
Write-Host 'Time to remediate'
@@ -72,23 +65,23 @@ function Invoke-CIPPStandardProfilePhotos {
7265
Write-Host 'Enabling'
7366
# Enable photo updates
7467
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OwaMailboxPolicy' -cmdParams @{Identity = $CurrentOWAState.Identity; SetPhotoEnabled = $true } -useSystemMailbox $true
75-
# $null = New-GraphRequest -uri $Uri -tenant $Tenant -type DELETE
68+
$null = New-GraphPostRequest -uri $Uri -tenant $Tenant -type DELETE -AsApp $true
7669
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set Profile photo settings to $StateValue" -sev Info
7770

7871
} else {
7972
Write-Host 'Disabling'
8073
# Disable photo updates
8174
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OwaMailboxPolicy' -cmdParams @{Identity = $CurrentOWAState.Identity; SetPhotoEnabled = $false } -useSystemMailbox $true
8275

83-
# $body = @{
84-
# source = 'cloud'
85-
# allowedRoles = @(
86-
# 'fe930be7-5e62-47db-91af-98c3a49a38b1', # Global admin
87-
# '62e90394-69f5-4237-9190-012177145e10' # User admin
88-
# )
89-
# }
90-
# $body = ConvertTo-Json -InputObject $body -Depth 5 -Compress
91-
# $null = New-GraphPostRequest -uri $Uri -tenant $Tenant -body $body -type PATCH -AsApp $true
76+
$body = @{
77+
source = 'cloud'
78+
allowedRoles = @(
79+
'fe930be7-5e62-47db-91af-98c3a49a38b1', # Global admin
80+
'62e90394-69f5-4237-9190-012177145e10' # User admin
81+
)
82+
}
83+
$body = ConvertTo-Json -InputObject $body -Depth 5 -Compress
84+
$null = New-GraphPostRequest -uri $Uri -tenant $Tenant -body $body -type PATCH -AsApp $true
9285
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Set Profile photo settings to $StateValue" -sev Info
9386
}
9487
} catch {
@@ -115,7 +108,10 @@ function Invoke-CIPPStandardProfilePhotos {
115108
if ($CurrentStatesCorrect) {
116109
$FieldValue = $true
117110
} else {
118-
$FieldValue = $CurrentOWAState
111+
$FieldValue = [PSCustomObject]@{
112+
OwaStateCorrect = $OWAStateCorrect
113+
GraphStateCorrect = $GraphStateCorrect
114+
}
119115
}
120116
Set-CIPPStandardsCompareField -FieldName 'standards.ProfilePhotos' -FieldValue $FieldValue -Tenant $Tenant
121117
}

0 commit comments

Comments
 (0)