@@ -42,25 +42,18 @@ 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
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
58
51
59
52
# Get current OWA mailbox policy state
60
53
$CurrentOWAState = New-ExoRequest - tenantid $Tenant - cmdlet ' Get-OwaMailboxPolicy' - cmdParams @ {Identity = ' OwaMailboxPolicy-Default' } - Select ' Identity,SetPhotoEnabled'
61
54
$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
64
57
65
58
if ($Settings.remediate -eq $true ) {
66
59
Write-Host ' Time to remediate'
@@ -72,23 +65,23 @@ function Invoke-CIPPStandardProfilePhotos {
72
65
Write-Host ' Enabling'
73
66
# Enable photo updates
74
67
$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
76
69
Write-LogMessage - API ' Standards' - tenant $Tenant - message " Set Profile photo settings to $StateValue " - sev Info
77
70
78
71
} else {
79
72
Write-Host ' Disabling'
80
73
# Disable photo updates
81
74
$null = New-ExoRequest - tenantid $Tenant - cmdlet ' Set-OwaMailboxPolicy' - cmdParams @ {Identity = $CurrentOWAState.Identity ; SetPhotoEnabled = $false } - useSystemMailbox $true
82
75
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
92
85
Write-LogMessage - API ' Standards' - tenant $Tenant - message " Set Profile photo settings to $StateValue " - sev Info
93
86
}
94
87
} catch {
@@ -115,7 +108,10 @@ function Invoke-CIPPStandardProfilePhotos {
115
108
if ($CurrentStatesCorrect ) {
116
109
$FieldValue = $true
117
110
} else {
118
- $FieldValue = $CurrentOWAState
111
+ $FieldValue = [PSCustomObject ]@ {
112
+ OwaStateCorrect = $OWAStateCorrect
113
+ GraphStateCorrect = $GraphStateCorrect
114
+ }
119
115
}
120
116
Set-CIPPStandardsCompareField - FieldName ' standards.ProfilePhotos' - FieldValue $FieldValue - Tenant $Tenant
121
117
}
0 commit comments