@@ -42,25 +42,23 @@ function Invoke-CIPPStandardProfilePhotos {
42
42
# true if wanted state is enabled, false if disabled
43
43
$DesiredState = $StateValue -eq ' enabled'
44
44
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
-
51
45
# 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
46
+ $Uri = ' https://graph.microsoft.com/beta/admin/people/photoUpdateSettings'
47
+ $CurrentGraphState = New-GraphGetRequest - uri $Uri - tenantid $Tenant
48
+ $UsersCanChangePhotos = if ([string ]::IsNullOrWhiteSpace($CurrentGraphState.allowedRoles ) ) { $true } else { $false }
49
+ $GraphStateCorrect = $UsersCanChangePhotos -eq $DesiredState
57
50
51
+ if ($UsersCanChangePhotos -eq $false -and $DesiredState -eq $false ) {
52
+ # Check if the correct roles are present
53
+ $GraphStateCorrect = $CurrentGraphState.allowedRoles -contains ' 62e90394-69f5-4237-9190-012177145e10' -and $CurrentGraphState.allowedRoles -contains ' fe930be7-5e62-47db-91af-98c3a49a38b1'
54
+ }
58
55
59
56
# Get current OWA mailbox policy state
60
57
$CurrentOWAState = New-ExoRequest - tenantid $Tenant - cmdlet ' Get-OwaMailboxPolicy' - cmdParams @ {Identity = ' OwaMailboxPolicy-Default' } - Select ' Identity,SetPhotoEnabled'
61
58
$OWAStateCorrect = $CurrentOWAState.SetPhotoEnabled -eq $DesiredState
62
- # $CurrentStatesCorrect = $GraphStateCorrect -eq $true -and $OWAStateCorrect -eq $true
63
- $CurrentStatesCorrect = $OWAStateCorrect -eq $true
59
+
60
+ # Check if both states are correct
61
+ $CurrentStatesCorrect = $GraphStateCorrect -eq $true -and $OWAStateCorrect -eq $true
64
62
65
63
if ($Settings.remediate -eq $true ) {
66
64
Write-Host ' Time to remediate'
@@ -72,23 +70,23 @@ function Invoke-CIPPStandardProfilePhotos {
72
70
Write-Host ' Enabling'
73
71
# Enable photo updates
74
72
$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
73
+ $null = New-GraphPostRequest - uri $Uri - tenant $Tenant - type DELETE - AsApp $true
76
74
Write-LogMessage - API ' Standards' - tenant $Tenant - message " Set Profile photo settings to $StateValue " - sev Info
77
75
78
76
} else {
79
77
Write-Host ' Disabling'
80
78
# Disable photo updates
81
79
$null = New-ExoRequest - tenantid $Tenant - cmdlet ' Set-OwaMailboxPolicy' - cmdParams @ {Identity = $CurrentOWAState.Identity ; SetPhotoEnabled = $false } - useSystemMailbox $true
82
80
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
81
+ $body = @ {
82
+ source = ' cloud'
83
+ allowedRoles = @ (
84
+ ' fe930be7-5e62-47db-91af-98c3a49a38b1' , # Global admin
85
+ ' 62e90394-69f5-4237-9190-012177145e10' # User admin
86
+ )
87
+ }
88
+ $body = ConvertTo-Json - InputObject $body - Depth 5 - Compress
89
+ $null = New-GraphPostRequest - uri $Uri - tenant $Tenant - body $body - type PATCH - AsApp $true
92
90
Write-LogMessage - API ' Standards' - tenant $Tenant - message " Set Profile photo settings to $StateValue " - sev Info
93
91
}
94
92
} catch {
@@ -115,7 +113,10 @@ function Invoke-CIPPStandardProfilePhotos {
115
113
if ($CurrentStatesCorrect ) {
116
114
$FieldValue = $true
117
115
} else {
118
- $FieldValue = $CurrentOWAState
116
+ $FieldValue = [PSCustomObject ]@ {
117
+ OwaStateCorrect = $OWAStateCorrect
118
+ GraphStateCorrect = $GraphStateCorrect
119
+ }
119
120
}
120
121
Set-CIPPStandardsCompareField - FieldName ' standards.ProfilePhotos' - FieldValue $FieldValue - Tenant $Tenant
121
122
}
0 commit comments