Skip to content

Commit 0321cd3

Browse files
authored
Merge pull request #436 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents ca3805f + fbe5f33 commit 0321cd3

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,37 @@ function Get-GraphRequestList {
349349
$Property = $BatchExpandQuery -replace '\?.*$', '' -replace '^.*\/', ''
350350
Write-Information "Performing batch expansion for property '$Property'..."
351351

352-
$Uri = "$Endpoint/{0}/$BatchExpandQuery"
352+
if ($Property -eq 'assignedLicenses') {
353+
$LicenseDetails = Get-CIPPLicenseOverview -TenantFilter $TenantFilter
354+
$GraphRequestResults = foreach ($GraphRequestResult in $GraphRequestResults) {
355+
$NewLicenses = [system.collections.generic.list[string]]::new()
356+
foreach ($License in $GraphRequestResult.assignedLicenses) {
357+
$LicenseInfo = $LicenseDetails | Where-Object { $_.skuId -eq $License.skuId } | Select-Object -First 1
358+
if ($LicenseInfo) {
359+
$NewLicenses.Add($LicenseInfo.License)
360+
}
361+
}
362+
$GraphRequestResult | Add-Member -MemberType NoteProperty -Name $Property -Value @($NewLicenses) -Force
363+
$GraphRequestResult
364+
}
365+
} else {
366+
367+
$Uri = "$Endpoint/{0}/$BatchExpandQuery"
353368

354-
$Requests = foreach ($Result in $GraphRequestResults) {
355-
@{
356-
id = $Result.id
357-
url = $Uri -f $Result.id
358-
method = 'GET'
369+
$Requests = foreach ($Result in $GraphRequestResults) {
370+
@{
371+
id = $Result.id
372+
url = $Uri -f $Result.id
373+
method = 'GET'
374+
}
359375
}
360-
}
361-
$BatchResults = New-GraphBulkRequest -Requests @($Requests) -tenantid $TenantFilter -NoAuthCheck $NoAuthCheck.IsPresent -asapp $AsApp
376+
$BatchResults = New-GraphBulkRequest -Requests @($Requests) -tenantid $TenantFilter -NoAuthCheck $NoAuthCheck.IsPresent -asapp $AsApp
362377

363-
$GraphRequestResults = foreach ($Result in $GraphRequestResults) {
364-
$PropValue = $BatchResults | Where-Object { $_.id -eq $Result.id } | Select-Object -ExpandProperty body
365-
$Result | Add-Member -MemberType NoteProperty -Name $Property -Value ($PropValue.value ?? $PropValue)
366-
$Result
378+
$GraphRequestResults = foreach ($Result in $GraphRequestResults) {
379+
$PropValue = $BatchResults | Where-Object { $_.id -eq $Result.id } | Select-Object -ExpandProperty body
380+
$Result | Add-Member -MemberType NoteProperty -Name $Property -Value ($PropValue.value ?? $PropValue)
381+
$Result
382+
}
367383
}
368384
}
369385
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardGroupTemplate.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ function Invoke-CIPPStandardGroupTemplate {
2828
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
2929
#>
3030
param($Tenant, $Settings)
31-
$TestResult = Test-CIPPStandardLicense -StandardName 'GroupTemplate' -TenantFilter $Tenant -RequiredCapabilities @('EXCHANGE_S_STANDARD', 'EXCHANGE_S_ENTERPRISE', 'EXCHANGE_S_STANDARD_GOV', 'EXCHANGE_S_ENTERPRISE_GOV', 'EXCHANGE_LITE') #No Foundation because that does not allow powershell access
31+
$TestResult = Test-CIPPStandardLicense -StandardName 'GroupTemplate' -TenantFilter $Tenant -RequiredCapabilities @('EXCHANGE_S_STANDARD', 'EXCHANGE_S_ENTERPRISE', 'EXCHANGE_S_STANDARD_GOV', 'EXCHANGE_S_ENTERPRISE_GOV', 'EXCHANGE_LITE') -SkipLog
3232

33-
if ($TestResult -eq $false) {
34-
Write-Host "We're exiting as the correct license is not present for this standard."
35-
return $true
36-
} #we're done.
3733
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'GroupTemplate'
3834
$existingGroups = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/groups?$top=999' -tenantid $tenant
3935
if ($Settings.remediate -eq $true) {
@@ -67,6 +63,11 @@ function Invoke-CIPPStandardGroupTemplate {
6763
if ($groupobj.groupType -in 'Generic', 'azurerole', 'dynamic', 'Security') {
6864
$GraphRequest = New-GraphPostRequest -uri 'https://graph.microsoft.com/beta/groups' -tenantid $tenant -type POST -body (ConvertTo-Json -InputObject $BodyToship -Depth 10) -verbose
6965
} else {
66+
if (!$TestResult) {
67+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Cannot create group $($groupobj.displayname) as the tenant is not licensed for Exchange." -Sev 'Error'
68+
continue
69+
}
70+
7071
if ($groupobj.groupType -eq 'dynamicdistribution') {
7172
$Params = @{
7273
Name = $groupobj.Displayname
@@ -92,6 +93,10 @@ function Invoke-CIPPStandardGroupTemplate {
9293
if ($groupobj.groupType -in 'Generic', 'azurerole', 'dynamic') {
9394
$GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/groups/$($CheckExististing.id)" -tenantid $tenant -type PATCH -body (ConvertTo-Json -InputObject $BodyToship -Depth 10) -verbose
9495
} else {
96+
if (!$TestResult) {
97+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Cannot update group $($groupobj.displayname) as the tenant is not licensed for Exchange." -Sev 'Error'
98+
continue
99+
}
95100
if ($groupobj.groupType -eq 'dynamicdistribution') {
96101
$Params = @{
97102
Name = $groupobj.Displayname

0 commit comments

Comments
 (0)