Skip to content

Commit c86da19

Browse files
Merge pull request KelvinTegelaar#1905 from Zacgoose/list-intune-by-tag
Fix: Optimise List Intune Templates by Tag
2 parents 3e4819b + 8a3fbc9 commit c86da19

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/MEM/Invoke-ListIntuneTemplates.ps1

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ function Invoke-ListIntuneTemplates {
5151
} else {
5252
if ($Request.query.mode -eq 'Tag') {
5353
#when the mode is tag, show all the potential tags, return the object with: label: tag, value: tag, count: number of templates with that tag, unique only
54-
$Templates = $RawTemplates | Where-Object { $_.Package } | Select-Object -Property Package | ForEach-Object {
55-
$package = $_.Package
54+
$Templates = @($RawTemplates | Where-Object { $_.Package } | Group-Object -Property Package | ForEach-Object {
55+
$package = $_.Name
56+
$packageTemplates = @($_.Group)
57+
$templateCount = $packageTemplates.Count
5658
[pscustomobject]@{
57-
label = "$($package) ($(($RawTemplates | Where-Object { $_.Package -eq $package }).Count) Templates)"
59+
label = "$($package) ($templateCount Templates)"
5860
value = $package
5961
type = 'tag'
60-
templateCount = ($RawTemplates | Where-Object { $_.Package -eq $package }).Count
61-
templates = @($RawTemplates | Where-Object { $_.Package -eq $package } | ForEach-Object {
62+
templateCount = $templateCount
63+
templates = @($packageTemplates | ForEach-Object {
6264
try {
6365
$JSONData = $_.JSON | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
6466
$data = $JSONData.RAWJson | ConvertFrom-Json -Depth 100 -ErrorAction SilentlyContinue
@@ -76,7 +78,7 @@ function Invoke-ListIntuneTemplates {
7678
}
7779
})
7880
}
79-
} | Sort-Object -Property label -Unique
81+
} | Sort-Object -Property label)
8082
} else {
8183
$Templates = $RawTemplates.JSON | ForEach-Object { try { ConvertFrom-Json -InputObject $_ -Depth 100 -ErrorAction SilentlyContinue } catch {} }
8284

0 commit comments

Comments
 (0)