Skip to content

Commit 473adbc

Browse files
authored
Merge pull request #481 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 5ce29a3 + 3f5025c commit 473adbc

File tree

9 files changed

+349
-121
lines changed

9 files changed

+349
-121
lines changed

Modules/CIPPCore/Public/Add-CIPPApplicationPermission.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ function Add-CIPPApplicationPermission {
44
$RequiredResourceAccess,
55
$TemplateId,
66
$ApplicationId,
7-
$Tenantfilter
7+
$TenantFilter
88
)
9-
if ($ApplicationId -eq $env:ApplicationID -and $Tenantfilter -eq $env:TenantID) {
9+
if ($ApplicationId -eq $env:ApplicationID -and $TenantFilter -eq $env:TenantID) {
1010
#return @('Cannot modify application permissions for CIPP-SAM on partner tenant')
1111
$RequiredResourceAccess = 'CIPPDefaults'
1212
}
@@ -60,18 +60,18 @@ function Add-CIPPApplicationPermission {
6060
}
6161

6262

63-
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=AppId,id,displayName&`$top=999" -skipTokenCache $true -tenantid $Tenantfilter -NoAuthCheck $true
63+
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=AppId,id,displayName&`$top=999" -skipTokenCache $true -tenantid $TenantFilter -NoAuthCheck $true
6464
$ourSVCPrincipal = $ServicePrincipalList | Where-Object -Property AppId -EQ $ApplicationId
6565
if (!$ourSVCPrincipal) {
6666
#Our Service Principal isn't available yet. We do a sleep and reexecute after 3 seconds.
6767
Start-Sleep -Seconds 5
68-
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=AppId,id,displayName&`$top=999" -skipTokenCache $true -tenantid $Tenantfilter -NoAuthCheck $true
68+
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=AppId,id,displayName&`$top=999" -skipTokenCache $true -tenantid $TenantFilter -NoAuthCheck $true
6969
$ourSVCPrincipal = $ServicePrincipalList | Where-Object -Property AppId -EQ $ApplicationId
7070
}
7171

7272
$Results = [System.Collections.Generic.List[string]]::new()
7373

74-
$CurrentRoles = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/appRoleAssignments" -tenantid $Tenantfilter -skipTokenCache $true -NoAuthCheck $true
74+
$CurrentRoles = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/appRoleAssignments" -tenantid $TenantFilter -skipTokenCache $true -NoAuthCheck $true
7575

7676
$Grants = foreach ($App in $RequiredResourceAccess) {
7777
$svcPrincipalId = $ServicePrincipalList | Where-Object -Property AppId -EQ $App.resourceAppId
@@ -80,7 +80,7 @@ function Add-CIPPApplicationPermission {
8080
$Body = @{
8181
appId = $App.resourceAppId
8282
} | ConvertTo-Json -Compress
83-
$svcPrincipalId = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/servicePrincipals' -tenantid $Tenantfilter -body $Body -type POST
83+
$svcPrincipalId = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/servicePrincipals' -tenantid $TenantFilter -body $Body -type POST
8484
} catch {
8585
$Results.add("Failed to create service principal for $($App.resourceAppId): $(Get-NormalizedError -message $_.Exception.Message)")
8686
continue
@@ -98,7 +98,7 @@ function Add-CIPPApplicationPermission {
9898
$counter = 0
9999
foreach ($Grant in $Grants) {
100100
try {
101-
$SettingsRequest = New-GraphPOSTRequest -body (ConvertTo-Json -InputObject $Grant -Depth 5) -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/appRoleAssignedTo" -tenantid $Tenantfilter -type POST -NoAuthCheck $true
101+
$SettingsRequest = New-GraphPOSTRequest -body (ConvertTo-Json -InputObject $Grant -Depth 5) -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/appRoleAssignedTo" -tenantid $TenantFilter -type POST -NoAuthCheck $true
102102
$counter++
103103
} catch {
104104
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message

Modules/CIPPCore/Public/Add-CIPPDelegatedPermission.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ function Add-CIPPDelegatedPermission {
55
$TemplateId,
66
$ApplicationId,
77
$NoTranslateRequired,
8-
$Tenantfilter
8+
$TenantFilter
99
)
1010
Write-Host 'Adding Delegated Permissions'
1111
Set-Location (Get-Item $PSScriptRoot).FullName
1212

13-
if ($ApplicationId -eq $env:ApplicationID -and $Tenantfilter -eq $env:TenantID) {
13+
if ($ApplicationId -eq $env:ApplicationID -and $TenantFilter -eq $env:TenantID) {
1414
#return @('Cannot modify delgated permissions for CIPP-SAM on partner tenant')
1515
$RequiredResourceAccess = 'CIPPDefaults'
1616
}
@@ -35,7 +35,7 @@ function Add-CIPPDelegatedPermission {
3535
$RequiredResourceAccess.Add($Resource)
3636
}
3737

38-
if ($Tenantfilter -eq $env:TenantID -or $Tenantfilter -eq 'PartnerTenant') {
38+
if ($TenantFilter -eq $env:TenantID -or $TenantFilter -eq 'PartnerTenant') {
3939
$RequiredResourceAccess = $RequiredResourceAccess + ($AdditionalPermissions | Where-Object { $RequiredResourceAccess.resourceAppId -notcontains $_.resourceAppId })
4040
} else {
4141
# remove the partner center permission if not pushing to partner tenant
@@ -70,11 +70,11 @@ function Add-CIPPDelegatedPermission {
7070
}
7171

7272
$Translator = Get-Content '.\PermissionsTranslator.json' | ConvertFrom-Json
73-
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=appId,id,displayName&`$top=999" -tenantid $Tenantfilter -skipTokenCache $true -NoAuthCheck $true
73+
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=appId,id,displayName&`$top=999" -tenantid $TenantFilter -skipTokenCache $true -NoAuthCheck $true
7474
$ourSVCPrincipal = $ServicePrincipalList | Where-Object -Property appId -EQ $ApplicationId
7575
$Results = [System.Collections.Generic.List[string]]::new()
7676

77-
$CurrentDelegatedScopes = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/oauth2PermissionGrants" -skipTokenCache $true -tenantid $Tenantfilter -NoAuthCheck $true
77+
$CurrentDelegatedScopes = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/oauth2PermissionGrants" -skipTokenCache $true -tenantid $TenantFilter -NoAuthCheck $true
7878

7979
foreach ($App in $RequiredResourceAccess) {
8080
if (!$App) {
@@ -86,7 +86,7 @@ function Add-CIPPDelegatedPermission {
8686
$Body = @{
8787
appId = $App.resourceAppId
8888
} | ConvertTo-Json -Compress
89-
$svcPrincipalId = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/v1.0/servicePrincipals' -tenantid $Tenantfilter -body $Body -type POST -NoAuthCheck $true
89+
$svcPrincipalId = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/v1.0/servicePrincipals' -tenantid $TenantFilter -body $Body -type POST -NoAuthCheck $true
9090
} catch {
9191
$Results.add("Failed to create service principal for $($App.resourceAppId): $(Get-NormalizedError -message $_.Exception.Message)")
9292
continue
@@ -125,7 +125,7 @@ function Add-CIPPDelegatedPermission {
125125
resourceId = $svcPrincipalId.id
126126
scope = $NewScope
127127
} | ConvertTo-Json -Compress
128-
$CreateRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/v1.0/oauth2PermissionGrants' -tenantid $Tenantfilter -body $Createbody -type POST -NoAuthCheck $true
128+
$CreateRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/v1.0/oauth2PermissionGrants' -tenantid $TenantFilter -body $Createbody -type POST -NoAuthCheck $true
129129
$Results.add("Successfully added permissions for $($svcPrincipalId.displayName)")
130130
} catch {
131131
$Results.add("Failed to add permissions for $($svcPrincipalId.displayName): $(Get-NormalizedError -message $_.Exception.Message)")
@@ -138,7 +138,7 @@ function Add-CIPPDelegatedPermission {
138138
$OldScope.id | ForEach-Object {
139139
if ($_ -ne $OldScopeId) {
140140
try {
141-
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/oauth2PermissionGrants/$_" -tenantid $Tenantfilter -type DELETE -NoAuthCheck $true
141+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/oauth2PermissionGrants/$_" -tenantid $TenantFilter -type DELETE -NoAuthCheck $true
142142
} catch {
143143
}
144144
}
@@ -162,7 +162,7 @@ function Add-CIPPDelegatedPermission {
162162
scope = "$NewScope"
163163
} | ConvertTo-Json -Compress
164164
try {
165-
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/oauth2PermissionGrants/$($OldScopeId)" -tenantid $Tenantfilter -body $Patchbody -type PATCH -NoAuthCheck $true
165+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/oauth2PermissionGrants/$($OldScopeId)" -tenantid $TenantFilter -body $Patchbody -type PATCH -NoAuthCheck $true
166166
} catch {
167167
$Results.add("Failed to update permissions for $($svcPrincipalId.displayName): $(Get-NormalizedError -message $_.Exception.Message)")
168168
continue

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecOnboardTenantQueue.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ function Push-ExecOnboardTenantQueue {
316316
$LastCPVError = ''
317317
do {
318318
try {
319-
Add-CIPPApplicationPermission -RequiredResourceAccess 'CIPPDefaults' -ApplicationId $env:ApplicationID -tenantfilter $Relationship.customer.tenantId
320-
Add-CIPPDelegatedPermission -RequiredResourceAccess 'CIPPDefaults' -ApplicationId $env:ApplicationID -tenantfilter $Relationship.customer.tenantId
319+
Add-CIPPApplicationPermission -RequiredResourceAccess 'CIPPDefaults' -ApplicationId $env:ApplicationID -TenantFilter $Relationship.customer.tenantId
320+
Add-CIPPDelegatedPermission -RequiredResourceAccess 'CIPPDefaults' -ApplicationId $env:ApplicationID -TenantFilter $Relationship.customer.tenantId
321321
$CPVSuccess = $true
322322
$Refreshing = $false
323323
} catch {
@@ -361,16 +361,16 @@ function Push-ExecOnboardTenantQueue {
361361
defaultDomainName = $Tenant.defaultDomainName
362362
}
363363
}
364-
$Table = Get-CippTable -tablename 'templates'
365-
$ExistingTemplates = Get-CippazDataTableEntity @Table -Filter "PartitionKey eq 'StandardsTemplateV2'" | Where-Object { $_.JSON -match 'AllTenants' }
364+
$Table = Get-CIPPTable -tablename 'templates'
365+
$ExistingTemplates = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'StandardsTemplateV2'" | Where-Object { $_.JSON -match 'AllTenants' }
366366
foreach ($AllTenantsTemplate in $ExistingTemplates) {
367367
$object = $AllTenantsTemplate.JSON | ConvertFrom-Json
368-
$NewExcludedTenants = [system.collections.generic.list[object]]::new()
368+
$NewExcludedTenants = [System.Collections.Generic.List[object]]::new()
369369
if (!$object.excludedTenants) {
370370
$object | Add-Member -MemberType NoteProperty -Name 'excludedTenants' -Value @() -Force
371371
}
372-
foreach ($Tenant in $object.excludedTenants) {
373-
$NewExcludedTenants.Add($Tenant)
372+
foreach ($ExcludedStandardsTenant in $object.excludedTenants) {
373+
$NewExcludedTenants.Add($ExcludedStandardsTenant)
374374
}
375375
$NewExcludedTenants.Add($AddExclusionObj)
376376
$object.excludedTenants = $NewExcludedTenants

0 commit comments

Comments
 (0)