Skip to content

Commit 732be33

Browse files
authored
Merge pull request #1312 from Ren-Roros-Digital/mdmscope
feat: New MDM User Scope standard
2 parents 7e8a67a + ca8aa46 commit 732be33

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

Modules/CIPPCore/Public/SAMManifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@
554554
{
555555
"id": "b7887744-6746-4312-813d-72daeaee7e2d",
556556
"type": "Scope"
557+
},
558+
{
559+
"id": "a8ead177-1889-4546-9387-f25e658e2a79",
560+
"type": "Scope"
557561
}
558562
]
559563
},
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
function Invoke-CIPPStandardMDMScope {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) MDMScope
7+
.SYNOPSIS
8+
(Label) Configure MDM user scope
9+
.DESCRIPTION
10+
(Helptext) Configures the MDM user scope. This also sets the terms of use, discovery and compliance URL to default URLs.
11+
(DocsDescription) Configures the MDM user scope. This also sets the terms of use URL, discovery URL and compliance URL to default values.
12+
.NOTES
13+
CAT
14+
Intune Standards
15+
TAG
16+
ADDEDCOMPONENT
17+
{"name":"appliesTo","label":"MDM User Scope?","type":"radio","options":[{"label":"All","value":"all"},{"label":"None","value":"none"},{"label":"Custom Group","value":"selected"}]}
18+
{"type":"textField","name":"standards.MDMScope.customGroup","label":"Custom Group Name","required":false}
19+
IMPACT
20+
Low Impact
21+
POWERSHELLEQUIVALENT
22+
Graph API
23+
RECOMMENDEDBY
24+
UPDATECOMMENTBLOCK
25+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
26+
.LINK
27+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/intune-standards#low-impact
28+
#>
29+
30+
param($Tenant, $Settings)
31+
32+
$CurrentInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000?$expand=includedGroups' -tenantid $Tenant
33+
34+
$StateIsCorrect = ($CurrentInfo.termsOfUseUrl -eq 'https://portal.manage.microsoft.com/TermsofUse.aspx') -and
35+
($CurrentInfo.discoveryUrl -eq 'https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc') -and
36+
($CurrentInfo.complianceUrl -eq 'https://portal.manage.microsoft.com/?portalAction=Compliance') -and
37+
($CurrentInfo.appliesTo -eq $Settings.appliesTo) -and
38+
($Settings.appliesTo -ne 'selected' -or ($CurrentInfo.includedGroups.displayName -contains $Settings.customGroup))
39+
40+
If ($Settings.remediate -eq $true) {
41+
if ($StateIsCorrect -eq $true) {
42+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'MDM Scope already correctly configured' -sev Info
43+
} else {
44+
$GraphParam = @{
45+
tenantid = $tenant
46+
Uri = 'https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000'
47+
ContentType = 'application/json; charset=utf-8'
48+
asApp = $false
49+
type = 'PATCH'
50+
AddedHeaders = @{'Accept-Language' = 0 }
51+
Body = @{
52+
'termsOfUseUrl' = 'https://portal.manage.microsoft.com/TermsofUse.aspx'
53+
'discoveryUrl' = 'https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc'
54+
'complianceUrl' = 'https://portal.manage.microsoft.com/?portalAction=Compliance'
55+
} | ConvertTo-Json
56+
}
57+
58+
try {
59+
New-GraphPostRequest @GraphParam
60+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Successfully configured MDM Scope' -sev Info
61+
} catch {
62+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
63+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to configure MDM Scope." -sev Error -LogData $ErrorMessage
64+
}
65+
66+
# 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."
67+
if ($Settings.appliesTo -ne 'selected') {
68+
$GraphParam = @{
69+
tenantid = $tenant
70+
Uri = 'https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000'
71+
ContentType = 'application/json; charset=utf-8'
72+
asApp = $false
73+
type = 'PATCH'
74+
AddedHeaders = @{'Accept-Language' = 0 }
75+
Body = @{
76+
'appliesTo' = $Settings.appliesTo
77+
} | ConvertTo-Json
78+
}
79+
80+
try {
81+
New-GraphPostRequest @GraphParam
82+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully assigned $($Settings.appliesTo) to MDM Scope" -sev Info
83+
} catch {
84+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
85+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to assign $($Settings.appliesTo) to MDM Scope." -sev Error -LogData $ErrorMessage
86+
}
87+
} else {
88+
$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
89+
$GraphParam = @{
90+
tenantid = $tenant
91+
Uri = 'https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000/includedGroups/$ref'
92+
ContentType = 'application/json; charset=utf-8'
93+
asApp = $false
94+
type = 'POST'
95+
AddedHeaders = @{'Accept-Language' = 0 }
96+
Body = @{
97+
'@odata.id' = "https://graph.microsoft.com/odata/groups('$GroupID')"
98+
} | ConvertTo-Json
99+
}
100+
101+
try {
102+
New-GraphPostRequest @GraphParam
103+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Successfully assigned $($Settings.customGroup) to MDM Scope" -sev Info
104+
} catch {
105+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
106+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to assign $($Settings.customGroup) to MDM Scope" -sev Error -LogData $ErrorMessage
107+
}
108+
}
109+
}
110+
}
111+
112+
if ($Settings.alert -eq $true -eq $true) {
113+
if ($StateIsCorrect) {
114+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'MDM Scope is correctly configured' -sev Info
115+
} else {
116+
Write-LogMessage -API 'Standards' -tenant $tenant -message 'MDM Scope is not correctly configured' -sev Alert
117+
}
118+
}
119+
120+
if ($Settings.report -eq $true) {
121+
Add-CIPPBPAField -FieldName 'MDMScope' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
122+
}
123+
124+
}

0 commit comments

Comments
 (0)