Skip to content

Commit 9e1c375

Browse files
authored
Merge pull request #913 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 852dab9 + 10656ae commit 9e1c375

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

Modules/CIPPCore/Public/Add-CIPPDelegatedPermission.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function Add-CIPPDelegatedPermission {
88
$TenantFilter
99
)
1010
Write-Information 'Adding Delegated Permissions'
11+
$ApplicationId = $ApplicationId ?? $env:ApplicationID
1112
Set-Location (Get-Item $PSScriptRoot).FullName
1213

1314
if ($ApplicationId -eq $env:ApplicationID -and $TenantFilter -eq $env:TenantID) {
@@ -77,9 +78,18 @@ function Add-CIPPDelegatedPermission {
7778
} else {
7879
New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=appId,id,displayName&`$top=999" -tenantid $TenantFilter -skipTokenCache $true -NoAuthCheck $true
7980
}
80-
$ourSVCPrincipal = $ServicePrincipalList | Where-Object -Property appId -EQ $ApplicationId
8181
$Results = [System.Collections.Generic.List[string]]::new()
8282

83+
$ourSVCPrincipal = $ServicePrincipalList | Where-Object -Property AppId -EQ $ApplicationId | Select-Object -First 1
84+
if (!$ourSVCPrincipal) {
85+
$ServicePrincipalList = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$select=appId,id,displayName&`$top=999" -tenantid $TenantFilter -skipTokenCache $true -NoAuthCheck $true
86+
$ourSVCPrincipal = $ServicePrincipalList | Where-Object -Property AppId -EQ $ApplicationId | Select-Object -First 1
87+
}
88+
if (!$ourSVCPrincipal) {
89+
$Results.Add("Failed to find service principal for application $ApplicationId in tenant $TenantFilter")
90+
return $Results
91+
}
92+
8393
$CurrentDelegatedScopes = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/oauth2PermissionGrants" -skipTokenCache $true -tenantid $TenantFilter -NoAuthCheck $true
8494

8595
foreach ($App in $RequiredResourceAccess) {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ExecScheduleForwardingVacation.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ function Invoke-ExecScheduleForwardingVacation {
4343
if ([string]::IsNullOrWhiteSpace($ForwardInternal)) {
4444
throw 'Forwarding target is required for internal forwarding.'
4545
}
46-
$SharedParams.ForwardInternal = $ForwardInternal
46+
$SharedParams | Add-Member -NotePropertyName 'ForwardInternal' -NotePropertyValue $ForwardInternal -Force
4747
$TargetValue = $ForwardInternal
4848
}
4949
'ExternalAddress' {
5050
if ([string]::IsNullOrWhiteSpace($ForwardExternal)) {
5151
throw 'Forwarding target is required for external forwarding.'
5252
}
53-
$SharedParams.ForwardExternal = $ForwardExternal
53+
$SharedParams | Add-Member -NotePropertyName 'ForwardExternal' -NotePropertyValue $ForwardExternal -Force
5454
$TargetValue = $ForwardExternal
5555
}
5656
default {

Modules/CIPPCore/Public/Get-TenantProperties.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@ function Get-TenantProperties {
44
)
55

66
$tableName = 'TenantProperties'
7-
$query = "PartitionKey eq '$customerId'"
87
$Table = Get-CIPPTable -TableName $tableName
9-
$tenantProperties = Get-CIPPAzDataTableEntity @Table -Filter $query
8+
9+
$SafeCustomerId = ConvertTo-CIPPODataFilterValue -Value $customerId -Type String
10+
$Query = "PartitionKey eq '$SafeCustomerId'"
11+
$tenantProperties = @(Get-CIPPAzDataTableEntity @Table -Filter $Query)
12+
13+
if ($tenantProperties.Count -eq 0 -and -not [string]::IsNullOrWhiteSpace($customerId)) {
14+
$Tenant = Get-Tenants -TenantFilter $customerId -IncludeErrors | Select-Object -First 1
15+
$ResolvedCustomerId = $Tenant.customerId
16+
17+
if (-not [string]::IsNullOrWhiteSpace($ResolvedCustomerId) -and $ResolvedCustomerId -ne $customerId) {
18+
$SafeResolvedCustomerId = ConvertTo-CIPPODataFilterValue -Value $ResolvedCustomerId -Type String
19+
$ResolvedQuery = "PartitionKey eq '$SafeResolvedCustomerId'"
20+
$tenantProperties = @(Get-CIPPAzDataTableEntity @Table -Filter $ResolvedQuery)
21+
}
22+
}
1023

1124
$properties = @{}
1225
foreach ($property in $tenantProperties) {

0 commit comments

Comments
 (0)