|
25 | 25 | @{ |
26 | 26 | id = 'ManagedAppPolicies' |
27 | 27 | method = 'GET' |
28 | | - url = '/deviceAppManagement/managedAppPolicies?$expand=assignments&$orderby=displayName' |
| 28 | + url = '/deviceAppManagement/managedAppPolicies?$orderby=displayName' |
29 | 29 | } |
30 | 30 | @{ |
31 | 31 | id = 'MobileAppConfigurations' |
|
41 | 41 |
|
42 | 42 | $GraphRequest = [System.Collections.Generic.List[object]]::new() |
43 | 43 |
|
44 | | - # Process Managed App Policies - these need separate assignment lookups |
| 44 | + # Process Managed App Policies - these need separate assignment lookups as the ManagedAppPolicies endpoint does not support $expand |
45 | 45 | $ManagedAppPolicies = ($BulkResults | Where-Object { $_.id -eq 'ManagedAppPolicies' }).body.value |
46 | 46 | if ($ManagedAppPolicies) { |
47 | | - # Build bulk requests for assignments of policies that support them |
48 | | - $AssignmentRequests = [System.Collections.Generic.List[object]]::new() |
49 | | - foreach ($Policy in $ManagedAppPolicies) { |
50 | | - # Only certain policy types support assignments endpoint |
51 | | - $odataType = $Policy.'@odata.type' |
52 | | - if ($odataType -match 'androidManagedAppProtection|iosManagedAppProtection|windowsManagedAppProtection|targetedManagedAppConfiguration') { |
53 | | - $urlSegment = switch -Wildcard ($odataType) { |
54 | | - '*androidManagedAppProtection*' { 'androidManagedAppProtections' } |
55 | | - '*iosManagedAppProtection*' { 'iosManagedAppProtections' } |
56 | | - '*windowsManagedAppProtection*' { 'windowsManagedAppProtections' } |
57 | | - '*targetedManagedAppConfiguration*' { 'targetedManagedAppConfigurations' } |
58 | | - } |
59 | | - if ($urlSegment) { |
60 | | - $AssignmentRequests.Add(@{ |
61 | | - id = $Policy.id |
62 | | - method = 'GET' |
63 | | - url = "/deviceAppManagement/$urlSegment('$($Policy.id)')/assignments" |
64 | | - }) |
| 47 | + # Get all @odata.type and deduplicate them |
| 48 | + $OdataTypes = ($ManagedAppPolicies | Select-Object -ExpandProperty '@odata.type' -Unique) -replace '#microsoft.graph.', '' |
| 49 | + $ManagedAppPoliciesBulkRequests = foreach ($type in $OdataTypes) { |
| 50 | + # Translate to URL segments |
| 51 | + $urlSegment = switch ($type) { |
| 52 | + 'androidManagedAppProtection' { 'androidManagedAppProtections' } |
| 53 | + 'iosManagedAppProtection' { 'iosManagedAppProtections' } |
| 54 | + 'mdmWindowsInformationProtectionPolicy' { 'mdmWindowsInformationProtectionPolicies' } |
| 55 | + 'windowsManagedAppProtection' { 'windowsManagedAppProtections' } |
| 56 | + 'targetedManagedAppConfiguration' { 'targetedManagedAppConfigurations' } |
| 57 | + default { $null } |
| 58 | + } |
| 59 | + Write-Information "Type: $type => URL Segment: $urlSegment" |
| 60 | + if ($urlSegment) { |
| 61 | + @{ |
| 62 | + id = $type |
| 63 | + method = 'GET' |
| 64 | + url = "/deviceAppManagement/${urlSegment}?`$expand=assignments&`$orderby=displayName" |
65 | 65 | } |
66 | 66 | } |
67 | 67 | } |
68 | 68 |
|
69 | | - # Fetch assignments in bulk if we have any |
70 | | - $AssignmentResults = @{} |
71 | | - if ($AssignmentRequests.Count -gt 0) { |
72 | | - $AssignmentBulkResults = New-GraphBulkRequest -Requests $AssignmentRequests -tenantid $TenantFilter |
73 | | - foreach ($result in $AssignmentBulkResults) { |
74 | | - if ($result.body.value) { |
75 | | - $AssignmentResults[$result.id] = $result.body.value |
76 | | - } |
77 | | - } |
| 69 | + $ManagedAppPoliciesBulkResults = New-GraphBulkRequest -Requests $ManagedAppPoliciesBulkRequests -tenantid $TenantFilter |
| 70 | + # Do this horriblenes as a workaround, as the results dont return with a odata.type property |
| 71 | + $ManagedAppPolicies = $ManagedAppPoliciesBulkResults | ForEach-Object { |
| 72 | + $URLName = $_.id |
| 73 | + $_.body.value | Add-Member -NotePropertyName 'URLName' -NotePropertyValue $URLName -Force |
| 74 | + $_.body.value |
78 | 75 | } |
79 | 76 |
|
| 77 | + |
| 78 | + |
80 | 79 | foreach ($Policy in $ManagedAppPolicies) { |
81 | | - $policyType = switch -Wildcard ($Policy.'@odata.type') { |
82 | | - '*androidManagedAppProtection*' { 'Android App Protection' } |
83 | | - '*iosManagedAppProtection*' { 'iOS App Protection' } |
84 | | - '*windowsManagedAppProtection*' { 'Windows App Protection' } |
85 | | - '*mdmWindowsInformationProtectionPolicy*' { 'Windows Information Protection (MDM)' } |
86 | | - '*windowsInformationProtectionPolicy*' { 'Windows Information Protection' } |
87 | | - '*targetedManagedAppConfiguration*' { 'App Configuration (MAM)' } |
88 | | - '*defaultManagedAppProtection*' { 'Default App Protection' } |
| 80 | + $policyType = switch ($Policy.'URLName') { |
| 81 | + 'androidManagedAppProtection' { 'Android App Protection'; break } |
| 82 | + 'iosManagedAppProtection' { 'iOS App Protection'; break } |
| 83 | + 'windowsManagedAppProtection' { 'Windows App Protection'; break } |
| 84 | + 'mdmWindowsInformationProtectionPolicy' { 'Windows Information Protection (MDM)'; break } |
| 85 | + 'windowsInformationProtectionPolicy' { 'Windows Information Protection'; break } |
| 86 | + 'targetedManagedAppConfiguration' { 'App Configuration (MAM)'; break } |
| 87 | + 'defaultManagedAppProtection' { 'Default App Protection'; break } |
89 | 88 | default { 'App Protection Policy' } |
90 | 89 | } |
91 | 90 |
|
92 | 91 | # Process assignments |
93 | 92 | $PolicyAssignment = [System.Collections.Generic.List[string]]::new() |
94 | 93 | $PolicyExclude = [System.Collections.Generic.List[string]]::new() |
95 | | - $Assignments = $AssignmentResults[$Policy.id] |
96 | | - if ($Assignments) { |
97 | | - foreach ($Assignment in $Assignments) { |
| 94 | + if ($Policy.assignments) { |
| 95 | + foreach ($Assignment in $Policy.assignments) { |
98 | 96 | $target = $Assignment.target |
99 | 97 | switch ($target.'@odata.type') { |
100 | 98 | '#microsoft.graph.allDevicesAssignmentTarget' { $PolicyAssignment.Add('All Devices') } |
|
112 | 110 | } |
113 | 111 |
|
114 | 112 | $Policy | Add-Member -NotePropertyName 'PolicyTypeName' -NotePropertyValue $policyType -Force |
115 | | - $Policy | Add-Member -NotePropertyName 'URLName' -NotePropertyValue 'managedAppPolicies' -Force |
| 113 | + # $Policy | Add-Member -NotePropertyName 'URLName' -NotePropertyValue 'managedAppPolicies' -Force |
116 | 114 | $Policy | Add-Member -NotePropertyName 'PolicySource' -NotePropertyValue 'AppProtection' -Force |
117 | 115 | $Policy | Add-Member -NotePropertyName 'PolicyAssignment' -NotePropertyValue ($PolicyAssignment -join ', ') -Force |
118 | 116 | $Policy | Add-Member -NotePropertyName 'PolicyExclude' -NotePropertyValue ($PolicyExclude -join ', ') -Force |
|
0 commit comments