@@ -33,7 +33,7 @@ function Invoke-CIPPStandardMDMScope {
3333
3434 $CurrentInfo = New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000?$expand=includedGroups' - tenantid $Tenant
3535
36- $StateIsCorrect = ($CurrentInfo.termsOfUseUrl -eq ' https://portal.manage.microsoft.com/TermsofUse.aspx' ) -and
36+ $StateIsCorrect = ($CurrentInfo.termsOfUseUrl -eq ' https://portal.manage.microsoft.com/TermsofUse.aspx' ) -and
3737 ($CurrentInfo.discoveryUrl -eq ' https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc' ) -and
3838 ($CurrentInfo.complianceUrl -eq ' https://portal.manage.microsoft.com/?portalAction=Compliance' ) -and
3939 ($CurrentInfo.appliesTo -eq $Settings.appliesTo ) -and
@@ -44,15 +44,15 @@ function Invoke-CIPPStandardMDMScope {
4444 Write-LogMessage - API ' Standards' - tenant $tenant - message ' MDM Scope already correctly configured' - sev Info
4545 } else {
4646 $GraphParam = @ {
47- tenantid = $tenant
48- Uri = ' https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000'
49- ContentType = ' application/json; charset=utf-8'
50- asApp = $false
51- type = ' PATCH'
47+ tenantid = $tenant
48+ Uri = ' https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000'
49+ ContentType = ' application/json; charset=utf-8'
50+ asApp = $false
51+ type = ' PATCH'
5252 AddedHeaders = @ {' Accept-Language' = 0 }
53- Body = @ {
53+ Body = @ {
5454 ' termsOfUseUrl' = ' https://portal.manage.microsoft.com/TermsofUse.aspx'
55- ' discoveryUrl' = ' https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc'
55+ ' discoveryUrl' = ' https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc'
5656 ' complianceUrl' = ' https://portal.manage.microsoft.com/?portalAction=Compliance'
5757 } | ConvertTo-Json
5858 }
@@ -62,19 +62,19 @@ function Invoke-CIPPStandardMDMScope {
6262 Write-LogMessage - API ' Standards' - tenant $tenant - message ' Successfully configured MDM Scope' - sev Info
6363 } catch {
6464 $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
65- Write-LogMessage - API ' Standards' - tenant $tenant - message " Failed to configure MDM Scope." - sev Error - LogData $ErrorMessage
65+ Write-LogMessage - API ' Standards' - tenant $tenant - message ' Failed to configure MDM Scope.' - sev Error - LogData $ErrorMessage
6666 }
6767
6868 # Workaround for MDM Scope Assignment error: "Could not set MDM Scope for [TENANT]: Simultaneous patch requests on both the appliesTo and URL properties are currently not supported."
6969 if ($Settings.appliesTo -ne ' selected' ) {
7070 $GraphParam = @ {
71- tenantid = $tenant
72- Uri = ' https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000'
73- ContentType = ' application/json; charset=utf-8'
74- asApp = $false
75- type = ' PATCH'
71+ tenantid = $tenant
72+ Uri = ' https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000'
73+ ContentType = ' application/json; charset=utf-8'
74+ asApp = $false
75+ type = ' PATCH'
7676 AddedHeaders = @ {' Accept-Language' = 0 }
77- Body = @ {
77+ Body = @ {
7878 ' appliesTo' = $Settings.appliesTo
7979 } | ConvertTo-Json
8080 }
@@ -89,13 +89,13 @@ function Invoke-CIPPStandardMDMScope {
8989 } else {
9090 $GroupID = (New-GraphGetRequest - Uri " https://graph.microsoft.com/beta/groups?`$ top=999&`$ select=id,displayName&`$ filter=displayName eq '$ ( $Settings.customGroup ) '" - tenantid $tenant - asApp $true ).id
9191 $GraphParam = @ {
92- tenantid = $tenant
93- Uri = ' https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000/includedGroups/$ref'
94- ContentType = ' application/json; charset=utf-8'
95- asApp = $false
96- type = ' POST'
92+ tenantid = $tenant
93+ Uri = ' https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000/includedGroups/$ref'
94+ ContentType = ' application/json; charset=utf-8'
95+ asApp = $false
96+ type = ' POST'
9797 AddedHeaders = @ {' Accept-Language' = 0 }
98- Body = @ {
98+ Body = @ {
9999 ' @odata.id' = " https://graph.microsoft.com/odata/groups('$GroupID ')"
100100 } | ConvertTo-Json
101101 }
@@ -115,12 +115,14 @@ function Invoke-CIPPStandardMDMScope {
115115 if ($StateIsCorrect ) {
116116 Write-LogMessage - API ' Standards' - tenant $tenant - message ' MDM Scope is correctly configured' - sev Info
117117 } else {
118- Write-StandardsAlert - message " MDM Scope is not correctly configured" - object $CurrentInfo - tenant $tenant - standardName ' MDMScope' - standardId $Settings.standardId
118+ Write-StandardsAlert - message ' MDM Scope is not correctly configured' - object $CurrentInfo - tenant $tenant - standardName ' MDMScope' - standardId $Settings.standardId
119119 Write-LogMessage - API ' Standards' - tenant $tenant - message ' MDM Scope is not correctly configured' - sev Info
120120 }
121121 }
122122
123123 if ($Settings.report -eq $true ) {
124+ $state = $StateIsCorrect ? $true : $CurrentInfo
125+ Set-CIPPStandardsCompareField - FieldName ' standards.MDMScope' - FieldValue $state - TenantFilter $Tenant
124126 Add-CIPPBPAField - FieldName ' MDMScope' - FieldValue $StateIsCorrect - StoreAs bool - Tenant $tenant
125127 }
126128
0 commit comments