@@ -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
0 commit comments