@@ -15,26 +15,31 @@ function Invoke-ListIntuneScript {
1515 $TenantFilter = $Request.Query.tenantFilter
1616 $Results = [System.Collections.Generic.List [System.Object ]]::new()
1717
18- $BulkRequests = [PSCustomObject ]@ (
18+ $BulkRequests = @ (
19+ @ {
20+ id = ' Groups'
21+ method = ' GET'
22+ url = ' /groups?$top=999&$select=id,displayName'
23+ }
1924 @ {
2025 id = ' Windows'
2126 method = ' GET'
22- url = ' /deviceManagement/deviceManagementScripts'
27+ url = ' /deviceManagement/deviceManagementScripts?$expand=assignments '
2328 }
2429 @ {
2530 id = ' MacOS'
2631 method = ' GET'
27- url = ' /deviceManagement/deviceShellScripts'
32+ url = ' /deviceManagement/deviceShellScripts?$expand=assignments '
2833 }
2934 @ {
3035 id = ' Remediation'
3136 method = ' GET'
32- url = ' /deviceManagement/deviceHealthScripts'
37+ url = ' /deviceManagement/deviceHealthScripts?$expand=assignments '
3338 }
3439 @ {
3540 id = ' Linux'
3641 method = ' GET'
37- url = ' /deviceManagement/configurationPolicies'
42+ url = ' /deviceManagement/configurationPolicies?$expand=assignments '
3843 }
3944 )
4045
@@ -45,6 +50,9 @@ function Invoke-ListIntuneScript {
4550 Write-Host " Failed to retrieve scripts. Error: $ ( $ErrorMessage.NormalizedError ) "
4651 }
4752
53+ # Extract groups for resolving assignment names
54+ $Groups = ($BulkResults | Where-Object { $_.id -eq ' Groups' }).body.value
55+
4856 foreach ($scriptId in @ (' Windows' , ' MacOS' , ' Remediation' , ' Linux' )) {
4957 $BulkResult = ($BulkResults | Where-Object { $_.id -eq $scriptId })
5058 if ($BulkResult.status -ne 200 ) {
@@ -65,6 +73,33 @@ function Invoke-ListIntuneScript {
6573 $scripts | ForEach-Object { $_ | Add-Member - MemberType NoteProperty - Name displayName - Value $_.name - Force }
6674 }
6775
76+ # Process assignments for each script
77+ foreach ($script in $scripts ) {
78+ $ScriptAssignment = [System.Collections.Generic.List [string ]]::new()
79+ $ScriptExclude = [System.Collections.Generic.List [string ]]::new()
80+
81+ if ($script.assignments ) {
82+ foreach ($Assignment in $script.assignments ) {
83+ $target = $Assignment.target
84+ switch ($target .' @odata.type' ) {
85+ ' #microsoft.graph.allDevicesAssignmentTarget' { $ScriptAssignment.Add (' All Devices' ) }
86+ ' #microsoft.graph.allLicensedUsersAssignmentTarget' { $ScriptAssignment.Add (' All Licensed Users' ) }
87+ ' #microsoft.graph.groupAssignmentTarget' {
88+ $groupName = ($Groups | Where-Object { $_.id -eq $target.groupId }).displayName
89+ if ($groupName ) { $ScriptAssignment.Add ($groupName ) }
90+ }
91+ ' #microsoft.graph.exclusionGroupAssignmentTarget' {
92+ $groupName = ($Groups | Where-Object { $_.id -eq $target.groupId }).displayName
93+ if ($groupName ) { $ScriptExclude.Add ($groupName ) }
94+ }
95+ }
96+ }
97+ }
98+
99+ $script | Add-Member - NotePropertyName ' ScriptAssignment' - NotePropertyValue ($ScriptAssignment -join ' , ' ) - Force
100+ $script | Add-Member - NotePropertyName ' ScriptExclude' - NotePropertyValue ($ScriptExclude -join ' , ' ) - Force
101+ }
102+
68103 $scripts | Add-Member - MemberType NoteProperty - Name scriptType - Value $scriptId
69104 Write-Host " $scriptId scripts count: $ ( $scripts.Count ) "
70105 $Results.AddRange (@ ($scripts ))
0 commit comments