Skip to content

Commit fbe5f33

Browse files
committed
only skip exchange groups if not licensed
Fixes KelvinTegelaar/CIPP#4569 Does not block group creation when security or other non-exchange types
1 parent 90940fa commit fbe5f33

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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)