Skip to content

Commit 1d9167c

Browse files
committed
feat: add feature update policy
also fix issue with spaces between commas for group assignment for esco
1 parent 236715d commit 1d9167c

File tree

4 files changed

+83
-52
lines changed

4 files changed

+83
-52
lines changed

Modules/CIPPCore/Public/Entrypoints/Invoke-ListIntunePolicy.ps1

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Function Invoke-ListIntunePolicy {
3838
method = 'GET'
3939
url = "/deviceManagement/windowsDriverUpdateProfiles?`$expand=assignments&top=200"
4040
}
41+
@{
42+
id = 'WindowsFeatureUpdateProfiles'
43+
method = 'GET'
44+
url = "/deviceManagement/windowsFeatureUpdateProfiles?`$expand=assignments&top=200"
45+
}
4146
@{
4247
id = 'GroupPolicyConfigurations'
4348
method = 'GET'
@@ -58,48 +63,49 @@ Function Invoke-ListIntunePolicy {
5863
$BulkResults = New-GraphBulkRequest -Requests $BulkRequests -tenantid $TenantFilter
5964

6065
$GraphRequest = $BulkResults | ForEach-Object {
61-
$URLName = $_.Id
62-
$_.body.Value | ForEach-Object {
63-
$policyTypeName = switch -Wildcard ($_.'[email protected]') {
64-
'*microsoft.graph.windowsIdentityProtectionConfiguration*' { 'Identity Protection' }
65-
'*microsoft.graph.windows10EndpointProtectionConfiguration*' { 'Endpoint Protection' }
66-
'*microsoft.graph.windows10CustomConfiguration*' { 'Custom' }
67-
'*microsoft.graph.windows10DeviceFirmwareConfigurationInterface*' { 'Firmware Configuration' }
68-
'*groupPolicyConfigurations*' { 'Administrative Templates' }
69-
'*windowsDomainJoinConfiguration*' { 'Domain Join configuration' }
70-
'*windowsUpdateForBusinessConfiguration*' { 'Update Configuration' }
71-
'*windowsHealthMonitoringConfiguration*' { 'Health Monitoring' }
72-
'*microsoft.graph.macOSGeneralDeviceConfiguration*' { 'MacOS Configuration' }
73-
'*microsoft.graph.macOSEndpointProtectionConfiguration*' { 'MacOS Endpoint Protection' }
74-
'*microsoft.graph.androidWorkProfileGeneralDeviceConfiguration*' { 'Android Configuration' }
75-
default { $_.'[email protected]' }
76-
}
77-
$Assignments = $_.assignments.target | Select-Object -Property '@odata.type', groupId
78-
$PolicyAssignment = [System.Collections.Generic.List[string]]::new()
79-
$PolicyExclude = [System.Collections.Generic.List[string]]::new()
80-
ForEach ($target in $Assignments) {
81-
switch ($target.'@odata.type') {
82-
'#microsoft.graph.allDevicesAssignmentTarget' { $PolicyAssignment.Add('All Devices') }
83-
'#microsoft.graph.exclusionallDevicesAssignmentTarget' { $PolicyExclude.Add('All Devices') }
84-
'#microsoft.graph.allUsersAssignmentTarget' { $PolicyAssignment.Add('All Users') }
85-
'#microsoft.graph.allLicensedUsersAssignmentTarget' { $PolicyAssignment.Add('All Licenced Users') }
86-
'#microsoft.graph.exclusionallUsersAssignmentTarget' { $PolicyExclude.Add('All Users') }
87-
'#microsoft.graph.groupAssignmentTarget' { $PolicyAssignment.Add($Groups.Where({ $_.id -eq $target.groupId }).displayName) }
88-
'#microsoft.graph.exclusionGroupAssignmentTarget' { $PolicyExclude.Add($Groups.Where({ $_.id -eq $target.groupId }).displayName) }
89-
default {
90-
$PolicyAssignment.Add($null)
91-
$PolicyExclude.Add($null)
92-
}
66+
$URLName = $_.Id
67+
$_.body.Value | ForEach-Object {
68+
$policyTypeName = switch -Wildcard ($_.'[email protected]') {
69+
'*microsoft.graph.windowsIdentityProtectionConfiguration*' { 'Identity Protection' }
70+
'*microsoft.graph.windows10EndpointProtectionConfiguration*' { 'Endpoint Protection' }
71+
'*microsoft.graph.windows10CustomConfiguration*' { 'Custom' }
72+
'*microsoft.graph.windows10DeviceFirmwareConfigurationInterface*' { 'Firmware Configuration' }
73+
'*groupPolicyConfigurations*' { 'Administrative Templates' }
74+
'*windowsDomainJoinConfiguration*' { 'Domain Join configuration' }
75+
'*windowsUpdateForBusinessConfiguration*' { 'Update Configuration' }
76+
'*windowsHealthMonitoringConfiguration*' { 'Health Monitoring' }
77+
'*microsoft.graph.macOSGeneralDeviceConfiguration*' { 'MacOS Configuration' }
78+
'*microsoft.graph.macOSEndpointProtectionConfiguration*' { 'MacOS Endpoint Protection' }
79+
'*microsoft.graph.androidWorkProfileGeneralDeviceConfiguration*' { 'Android Configuration' }
80+
'*windowsFeatureUpdateProfiles*' { 'Feature Update' }
81+
default { $_.'[email protected]' }
82+
}
83+
$Assignments = $_.assignments.target | Select-Object -Property '@odata.type', groupId
84+
$PolicyAssignment = [System.Collections.Generic.List[string]]::new()
85+
$PolicyExclude = [System.Collections.Generic.List[string]]::new()
86+
ForEach ($target in $Assignments) {
87+
switch ($target.'@odata.type') {
88+
'#microsoft.graph.allDevicesAssignmentTarget' { $PolicyAssignment.Add('All Devices') }
89+
'#microsoft.graph.exclusionallDevicesAssignmentTarget' { $PolicyExclude.Add('All Devices') }
90+
'#microsoft.graph.allUsersAssignmentTarget' { $PolicyAssignment.Add('All Users') }
91+
'#microsoft.graph.allLicensedUsersAssignmentTarget' { $PolicyAssignment.Add('All Licenced Users') }
92+
'#microsoft.graph.exclusionallUsersAssignmentTarget' { $PolicyExclude.Add('All Users') }
93+
'#microsoft.graph.groupAssignmentTarget' { $PolicyAssignment.Add($Groups.Where({ $_.id -eq $target.groupId }).displayName) }
94+
'#microsoft.graph.exclusionGroupAssignmentTarget' { $PolicyExclude.Add($Groups.Where({ $_.id -eq $target.groupId }).displayName) }
95+
default {
96+
$PolicyAssignment.Add($null)
97+
$PolicyExclude.Add($null)
9398
}
9499
}
95-
if ($null -eq $_.displayname) { $_ | Add-Member -NotePropertyName displayName -NotePropertyValue $_.name }
96-
$_ | Add-Member -NotePropertyName PolicyTypeName -NotePropertyValue $policyTypeName
97-
$_ | Add-Member -NotePropertyName URLName -NotePropertyValue $URLName
98-
$_ | Add-Member -NotePropertyName PolicyAssignment -NotePropertyValue ($PolicyAssignment -join ', ')
99-
$_ | Add-Member -NotePropertyName PolicyExclude -NotePropertyValue ($PolicyExclude -join ', ')
100-
$_
101-
} | Where-Object { $null -ne $_.DisplayName }
102-
}
100+
}
101+
if ($null -eq $_.displayname) { $_ | Add-Member -NotePropertyName displayName -NotePropertyValue $_.name }
102+
$_ | Add-Member -NotePropertyName PolicyTypeName -NotePropertyValue $policyTypeName
103+
$_ | Add-Member -NotePropertyName URLName -NotePropertyValue $URLName
104+
$_ | Add-Member -NotePropertyName PolicyAssignment -NotePropertyValue ($PolicyAssignment -join ', ')
105+
$_ | Add-Member -NotePropertyName PolicyExclude -NotePropertyValue ($PolicyExclude -join ', ')
106+
$_
107+
} | Where-Object { $null -ne $_.DisplayName }
108+
}
103109
}
104110

105111
# Filter the results to sort out linux scripts

Modules/CIPPCore/Public/New-CIPPIntuneTemplate.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ function New-CIPPIntuneTemplate {
9797

9898
$TemplateJson = (ConvertTo-Json -InputObject $inputvar -Depth 100 -Compress)
9999
}
100+
'windowsFeatureUpdateProfiles' {
101+
$Type = 'windowsFeatureUpdateProfiles'
102+
$Template = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceManagement/$($urlname)/$($ID)" -tenantid $tenantfilter | Select-Object * -ExcludeProperty id, lastModifiedDateTime, '@odata.context', 'ScopeTagIds', 'supportsScopeTags', 'createdDateTime'
103+
$DisplayName = $Template.displayName
104+
$TemplateJson = ConvertTo-Json -InputObject $Template -Depth 100 -Compress
105+
}
100106
}
101107
return [PSCustomObject]@{
102108
TemplateJson = $TemplateJson

Modules/CIPPCore/Public/Set-CIPPAssignedPolicy.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ function Set-CIPPAssignedPolicy {
5252
}
5353
default {
5454
Write-Host "We're supposed to assign a custom group. The group is $GroupName"
55-
$GroupNames = $GroupName.Split(',')
55+
$GroupNames = $GroupName -split '\s,\s'
5656
$GroupIds = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/groups?$select=id,displayName&$top=999' -tenantid $TenantFilter |
57-
ForEach-Object {
58-
foreach ($SingleName in $GroupNames) {
59-
if ($_.displayName -like $SingleName) {
60-
$_.id
57+
ForEach-Object {
58+
foreach ($SingleName in $GroupNames) {
59+
if ($_.displayName -like $SingleName) {
60+
$_.id
61+
}
6162
}
6263
}
63-
}
6464
foreach ($gid in $GroupIds) {
6565
$assignmentsList.Add(
6666
@{
@@ -75,15 +75,15 @@ function Set-CIPPAssignedPolicy {
7575
}
7676
if ($ExcludeGroup) {
7777
Write-Host "We're supposed to exclude a custom group. The group is $ExcludeGroup"
78-
$ExcludeGroupNames = $ExcludeGroup.Split(',')
78+
$ExcludeGroupNames = $GroupName -split '\s,\s'
7979
$ExcludeGroupIds = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/groups?$select=id,displayName&$top=999' -tenantid $TenantFilter |
80-
ForEach-Object {
81-
foreach ($SingleName in $ExcludeGroupNames) {
82-
if ($_.displayName -like $SingleName) {
83-
$_.id
80+
ForEach-Object {
81+
foreach ($SingleName in $ExcludeGroupNames) {
82+
if ($_.displayName -like $SingleName) {
83+
$_.id
84+
}
8485
}
8586
}
86-
}
8787

8888
foreach ($egid in $ExcludeGroupIds) {
8989
$assignmentsList.Add(

Modules/CIPPCore/Public/Set-CIPPIntunePolicy.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ function Set-CIPPIntunePolicy {
135135
Write-LogMessage -headers $Headers -API $APINAME -tenant $($tenantFilter) -message "Added policy $($DisplayName) via template" -Sev 'info'
136136
}
137137
}
138+
'windowsFeatureUpdateProfiles' {
139+
$PlatformType = 'deviceManagement'
140+
$TemplateTypeURL = 'windowsFeatureUpdateProfiles'
141+
$File = ($RawJSON | ConvertFrom-Json)
142+
$DisplayName = $File.displayName ?? $File.Name
143+
$CheckExististing = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter
144+
if ($DisplayName -in $CheckExististing.displayName) {
145+
$PostType = 'edited'
146+
$ExistingID = $CheckExististing | Where-Object -Property displayName -EQ $displayname
147+
Write-Host 'We are editing'
148+
$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL/$($ExistingID.Id)" -tenantid $tenantFilter -type PUT -body $RawJSON
149+
$CreateRequest = $CheckExististing | Where-Object -Property displayName -EQ $DisplayName
150+
151+
} else {
152+
$PostType = 'added'
153+
$CreateRequest = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/$PlatformType/$TemplateTypeURL" -tenantid $tenantFilter -type POST -body $RawJSON
154+
Write-LogMessage -headers $Headers -API $APINAME -tenant $($tenantFilter) -message "Added policy $($DisplayName) via template" -Sev 'info'
155+
}
156+
}
138157

139158
}
140159
Write-LogMessage -headers $Headers -API $APINAME -tenant $($tenantFilter) -message "$($PostType) policy $($Displayname)" -Sev 'Info'

0 commit comments

Comments
 (0)