@@ -6,126 +6,132 @@ function Set-CIPPIntunePolicy {
6
6
$DisplayName ,
7
7
$RawJSON ,
8
8
$AssignTo ,
9
- $excludeGroup ,
9
+ $ExcludeGroup ,
10
10
$Headers ,
11
11
$APINAME ,
12
12
$tenantFilter
13
13
)
14
14
try {
15
15
switch ($TemplateType ) {
16
16
' AppProtection' {
17
+ $PlatformType = ' deviceAppManagement'
17
18
$TemplateType = ($RawJSON | ConvertFrom-Json ).' @odata.type' -replace ' #microsoft.graph.' , ' '
18
19
$PolicyFile = $RawJSON | ConvertFrom-Json
19
20
$Null = $PolicyFile | Add-Member - MemberType NoteProperty - Name ' description' - Value $description - Force
20
21
$null = $PolicyFile | Add-Member - MemberType NoteProperty - Name ' displayName' - Value $displayname - Force
21
22
$RawJSON = ConvertTo-Json - InputObject $PolicyFile - Depth 20
22
23
$TemplateTypeURL = if ($TemplateType -eq ' windowsInformationProtectionPolicy' ) { ' windowsInformationProtectionPolicies' } else { " $ ( $TemplateType ) s" }
23
- $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/deviceAppManagement /$TemplateTypeURL " - tenantid $tenantFilter
24
+ $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
24
25
if ($displayname -in $CheckExististing.displayName ) {
25
26
$PostType = ' edited'
26
27
$ExistingID = $CheckExististing | Where-Object - Property displayName -EQ $displayname
27
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceAppManagement /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PATCH - body $RawJSON
28
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PATCH - body $RawJSON
28
29
$CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
29
30
} else {
30
31
$PostType = ' added'
31
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceAppManagement /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
32
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
32
33
}
33
34
}
34
35
' deviceCompliancePolicies' {
36
+ $PlatformType = ' deviceManagement'
35
37
$TemplateTypeURL = ' deviceCompliancePolicies'
36
- $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter
38
+ $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
37
39
$JSON = $RawJSON | ConvertFrom-Json | Select-Object * - ExcludeProperty id
, createdDateTime
, lastModifiedDateTime
, version
, ' [email protected] ' , ' @odata.context'
38
40
$JSON.scheduledActionsForRule = @ (
$JSON.scheduledActionsForRule | Select-Object * - ExcludeProperty
' [email protected] ' )
39
41
if ($displayname -in $CheckExististing.displayName ) {
40
42
$RawJSON = ConvertTo-Json - InputObject ($JSON | Select-Object * - ExcludeProperty ' scheduledActionsForRule' ) - Depth 20 - Compress
41
43
$PostType = ' edited'
42
44
$ExistingID = $CheckExististing | Where-Object - Property displayName -EQ $displayname
43
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PATCH - body $RawJSON
45
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PATCH - body $RawJSON
44
46
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Updated policy $ ( $DisplayName ) to template defaults" - Sev ' info'
45
47
$CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
46
48
} else {
47
49
$RawJSON = ConvertTo-Json - InputObject $JSON - Depth 20 - Compress
48
50
$PostType = ' added'
49
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
51
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
50
52
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
51
53
}
52
54
}
53
55
' Admin' {
56
+ $PlatformType = ' deviceManagement'
54
57
$TemplateTypeURL = ' groupPolicyConfigurations'
55
58
$CreateBody = ' {"description":"' + $description + ' ","displayName":"' + $displayname + ' ","roleScopeTagIds":["0"]}'
56
- $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter
59
+ $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
57
60
if ($displayname -in $CheckExististing.displayName ) {
58
61
$ExistingID = $CheckExististing | Where-Object - Property displayName -EQ $displayname
59
- $ExistingData = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL ('$ ( $ExistingID.id ) ')/definitionValues" - tenantid $tenantFilter
62
+ $ExistingData = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $ExistingID.id ) ')/definitionValues" - tenantid $tenantFilter
60
63
$DeleteJson = $RawJSON | ConvertFrom-Json - Depth 10
61
64
$DeleteJson.deletedIds = @ ($ExistingData.id )
62
65
$DeleteJson.added = @ ()
63
66
$DeleteJson = ConvertTo-Json - Depth 10 - InputObject $DeleteJson
64
- $DeleteRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL ('$ ( $ExistingID.id ) ')/updateDefinitionValues" - tenantid $tenantFilter - type POST - body $DeleteJson
65
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL ('$ ( $ExistingID.id ) ')/updateDefinitionValues" - tenantid $tenantFilter - type POST - body $RawJSON
67
+ $DeleteRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $ExistingID.id ) ')/updateDefinitionValues" - tenantid $tenantFilter - type POST - body $DeleteJson
68
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $ExistingID.id ) ')/updateDefinitionValues" - tenantid $tenantFilter - type POST - body $RawJSON
66
69
$CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
67
70
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Updated policy $ ( $Displayname ) to template defaults" - Sev ' info'
68
71
$PostType = ' edited'
69
72
} else {
70
73
$PostType = ' added'
71
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $CreateBody
72
- $UpdateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL ('$ ( $CreateRequest.id ) ')/updateDefinitionValues" - tenantid $tenantFilter - type POST - body $RawJSON
74
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $CreateBody
75
+ $UpdateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL ('$ ( $CreateRequest.id ) ')/updateDefinitionValues" - tenantid $tenantFilter - type POST - body $RawJSON
73
76
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $Displayname ) to template defaults" - Sev ' info'
74
77
75
78
}
76
79
}
77
80
' Device' {
81
+ $PlatformType = ' deviceManagement'
78
82
$TemplateTypeURL = ' deviceConfigurations'
79
83
$PolicyFile = $RawJSON | ConvertFrom-Json
80
84
$Null = $PolicyFile | Add-Member - MemberType NoteProperty - Name ' description' - Value " $description " - Force
81
85
$null = $PolicyFile | Add-Member - MemberType NoteProperty - Name ' displayName' - Value $displayname - Force
82
- $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter
86
+ $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
83
87
$ExistingID = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName | Select-Object - Last 1
84
88
$PolicyFile = $policyFile | Select-Object * - ExcludeProperty ' featureUpdatesWillBeRolledBack' , ' qualityUpdatesWillBeRolledBack' , ' qualityUpdatesPauseStartDate' , ' featureUpdatesPauseStartDate'
85
89
$RawJSON = ConvertTo-Json - InputObject $PolicyFile - Depth 100 - Compress
86
90
if ($ExistingID ) {
87
91
$PostType = ' edited'
88
92
Write-Host " Raw JSON is $RawJSON "
89
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PATCH - body $RawJSON
93
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PATCH - body $RawJSON
90
94
$CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
91
95
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Updated policy $ ( $DisplayName ) to template defaults" - Sev ' info'
92
96
} else {
93
97
$PostType = ' added'
94
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
98
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
95
99
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
96
100
97
101
}
98
102
}
99
103
' Catalog' {
104
+ $PlatformType = ' deviceManagement'
100
105
$TemplateTypeURL = ' configurationPolicies'
101
106
$DisplayName = ($RawJSON | ConvertFrom-Json ).Name
102
- $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter
107
+ $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
103
108
if ($DisplayName -in $CheckExististing.name ) {
104
109
$ExistingID = $CheckExististing | Where-Object - Property Name -EQ $DisplayName
105
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PUT - body $RawJSON
110
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PUT - body $RawJSON
106
111
$CreateRequest = $CheckExististing | Where-Object - Property Name -EQ $DisplayName
107
112
$PostType = ' edited'
108
113
} else {
109
114
$PostType = ' added'
110
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
115
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
111
116
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
112
117
}
113
118
}
114
119
' windowsDriverUpdateProfiles' {
120
+ $PlatformType = ' deviceManagement'
115
121
$TemplateTypeURL = ' windowsDriverUpdateProfiles'
116
122
$File = ($RawJSON | ConvertFrom-Json )
117
123
$DisplayName = $File.displayName ?? $File.Name
118
- $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter
124
+ $CheckExististing = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter
119
125
if ($DisplayName -in $CheckExististing.displayName ) {
120
126
$PostType = ' edited'
121
127
$ExistingID = $CheckExististing | Where-Object - Property displayName -EQ $displayname
122
128
Write-Host ' We are editing'
123
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PUT - body $RawJSON
129
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL /$ ( $ExistingID.Id ) " - tenantid $tenantFilter - type PUT - body $RawJSON
124
130
$CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
125
131
126
132
} else {
127
133
$PostType = ' added'
128
- $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/deviceManagement /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
134
+ $CreateRequest = New-GraphPOSTRequest - uri " https://graph.microsoft.com/beta/$PlatformType /$TemplateTypeURL " - tenantid $tenantFilter - type POST - body $RawJSON
129
135
Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
130
136
}
131
137
}
@@ -136,7 +142,7 @@ function Set-CIPPIntunePolicy {
136
142
Write-Host " Assigning policy to $ ( $AssignTo ) with ID $ ( $CreateRequest.id ) and type $TemplateTypeURL for tenant $tenantFilter "
137
143
Write-Host " ID is $ ( $CreateRequest.id ) "
138
144
139
- Set-CIPPAssignedPolicy - GroupName $AssignTo - PolicyId $CreateRequest.id - Type $TemplateTypeURL - TenantFilter $tenantFilter - excludeGroup $excludeGroup
145
+ Set-CIPPAssignedPolicy - GroupName $AssignTo - PolicyId $CreateRequest.id - PlatformType $PlatformType - Type $TemplateTypeURL - TenantFilter $tenantFilter - ExcludeGroup $ExcludeGroup
140
146
}
141
147
return " Successfully $ ( $PostType ) policy for $ ( $tenantFilter ) with display name $ ( $Displayname ) "
142
148
} catch {
0 commit comments