@@ -6,126 +6,132 @@ function Set-CIPPIntunePolicy {
66 $DisplayName ,
77 $RawJSON ,
88 $AssignTo ,
9- $excludeGroup ,
9+ $ExcludeGroup ,
1010 $Headers ,
1111 $APINAME ,
1212 $tenantFilter
1313 )
1414 try {
1515 switch ($TemplateType ) {
1616 ' AppProtection' {
17+ $PlatformType = ' deviceAppManagement'
1718 $TemplateType = ($RawJSON | ConvertFrom-Json ).' @odata.type' -replace ' #microsoft.graph.' , ' '
1819 $PolicyFile = $RawJSON | ConvertFrom-Json
1920 $Null = $PolicyFile | Add-Member - MemberType NoteProperty - Name ' description' - Value $description - Force
2021 $null = $PolicyFile | Add-Member - MemberType NoteProperty - Name ' displayName' - Value $displayname - Force
2122 $RawJSON = ConvertTo-Json - InputObject $PolicyFile - Depth 20
2223 $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
2425 if ($displayname -in $CheckExististing.displayName ) {
2526 $PostType = ' edited'
2627 $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
2829 $CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
2930 } else {
3031 $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
3233 }
3334 }
3435 ' deviceCompliancePolicies' {
36+ $PlatformType = ' deviceManagement'
3537 $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
3739 $JSON = $RawJSON | ConvertFrom-Json | Select-Object * - ExcludeProperty id
, createdDateTime
, lastModifiedDateTime
, version
, ' [email protected] ' , ' @odata.context' 3840 $JSON.scheduledActionsForRule = @ (
$JSON.scheduledActionsForRule | Select-Object * - ExcludeProperty
' [email protected] ' )
3941 if ($displayname -in $CheckExististing.displayName ) {
4042 $RawJSON = ConvertTo-Json - InputObject ($JSON | Select-Object * - ExcludeProperty ' scheduledActionsForRule' ) - Depth 20 - Compress
4143 $PostType = ' edited'
4244 $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
4446 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Updated policy $ ( $DisplayName ) to template defaults" - Sev ' info'
4547 $CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
4648 } else {
4749 $RawJSON = ConvertTo-Json - InputObject $JSON - Depth 20 - Compress
4850 $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
5052 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
5153 }
5254 }
5355 ' Admin' {
56+ $PlatformType = ' deviceManagement'
5457 $TemplateTypeURL = ' groupPolicyConfigurations'
5558 $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
5760 if ($displayname -in $CheckExististing.displayName ) {
5861 $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
6063 $DeleteJson = $RawJSON | ConvertFrom-Json - Depth 10
6164 $DeleteJson.deletedIds = @ ($ExistingData.id )
6265 $DeleteJson.added = @ ()
6366 $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
6669 $CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
6770 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Updated policy $ ( $Displayname ) to template defaults" - Sev ' info'
6871 $PostType = ' edited'
6972 } else {
7073 $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
7376 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $Displayname ) to template defaults" - Sev ' info'
7477
7578 }
7679 }
7780 ' Device' {
81+ $PlatformType = ' deviceManagement'
7882 $TemplateTypeURL = ' deviceConfigurations'
7983 $PolicyFile = $RawJSON | ConvertFrom-Json
8084 $Null = $PolicyFile | Add-Member - MemberType NoteProperty - Name ' description' - Value " $description " - Force
8185 $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
8387 $ExistingID = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName | Select-Object - Last 1
8488 $PolicyFile = $policyFile | Select-Object * - ExcludeProperty ' featureUpdatesWillBeRolledBack' , ' qualityUpdatesWillBeRolledBack' , ' qualityUpdatesPauseStartDate' , ' featureUpdatesPauseStartDate'
8589 $RawJSON = ConvertTo-Json - InputObject $PolicyFile - Depth 100 - Compress
8690 if ($ExistingID ) {
8791 $PostType = ' edited'
8892 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
9094 $CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
9195 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Updated policy $ ( $DisplayName ) to template defaults" - Sev ' info'
9296 } else {
9397 $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
9599 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
96100
97101 }
98102 }
99103 ' Catalog' {
104+ $PlatformType = ' deviceManagement'
100105 $TemplateTypeURL = ' configurationPolicies'
101106 $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
103108 if ($DisplayName -in $CheckExististing.name ) {
104109 $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
106111 $CreateRequest = $CheckExististing | Where-Object - Property Name -EQ $DisplayName
107112 $PostType = ' edited'
108113 } else {
109114 $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
111116 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
112117 }
113118 }
114119 ' windowsDriverUpdateProfiles' {
120+ $PlatformType = ' deviceManagement'
115121 $TemplateTypeURL = ' windowsDriverUpdateProfiles'
116122 $File = ($RawJSON | ConvertFrom-Json )
117123 $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
119125 if ($DisplayName -in $CheckExististing.displayName ) {
120126 $PostType = ' edited'
121127 $ExistingID = $CheckExististing | Where-Object - Property displayName -EQ $displayname
122128 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
124130 $CreateRequest = $CheckExististing | Where-Object - Property displayName -EQ $DisplayName
125131
126132 } else {
127133 $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
129135 Write-LogMessage - headers $Headers - API $APINAME - tenant $ ($tenantFilter ) - message " Added policy $ ( $DisplayName ) via template" - Sev ' info'
130136 }
131137 }
@@ -136,7 +142,7 @@ function Set-CIPPIntunePolicy {
136142 Write-Host " Assigning policy to $ ( $AssignTo ) with ID $ ( $CreateRequest.id ) and type $TemplateTypeURL for tenant $tenantFilter "
137143 Write-Host " ID is $ ( $CreateRequest.id ) "
138144
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
140146 }
141147 return " Successfully $ ( $PostType ) policy for $ ( $tenantFilter ) with display name $ ( $Displayname ) "
142148 } catch {
0 commit comments