Skip to content

Commit c82a76a

Browse files
authored
Merge pull request KelvinTegelaar#983 from KelvinTegelaar/dev
Dev to hotfix
2 parents eb1c02a + 4c5059d commit c82a76a

14 files changed

Lines changed: 95 additions & 64 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ function Push-GetTenantDomains {
22
Param($Item)
33
$DomainTable = Get-CippTable -tablename 'Domains'
44
$Filter = "PartitionKey eq 'TenantDomains' and TenantGUID eq '{0}'" -f $Item.TenantGUID
5-
$Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter -Property RowKey | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } }
5+
$Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter -Property PartitionKey, RowKey | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } }
66
return @($Domains)
7-
}
7+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ function Push-GetPendingWebhooks {
55
#>
66
Param($Item)
77
$Table = Get-CIPPTable -TableName WebhookIncoming
8-
$Webhooks = Get-CIPPAzDataTableEntity @Table -Property RowKey, FunctionName -First 10000
8+
$Webhooks = Get-CIPPAzDataTableEntity @Table -Property PartitionKey, RowKey, FunctionName -First 10000
99
$WebhookCount = ($Webhooks | Measure-Object).Count
1010
$Message = 'Processing {0} webhooks' -f $WebhookCount
1111
Write-LogMessage -API 'Webhooks' -message $Message -sev Info
1212
return $Webhooks
13-
}
13+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecDurableFunctions.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Invoke-ExecDurableFunctions {
5151
if ($Request.Query.PartitionKey) {
5252
$HistoryTable = Get-CippTable -TableName ('{0}History' -f $FunctionName)
5353
$Filter = "PartitionKey eq '{0}'" -f $Request.Query.PartitionKey
54-
$History = Get-CippAzDataTableEntity @HistoryTable -Filter $Filter -Property RowKey, Timestamp, EventType, Name, IsPlayed, OrchestrationStatus | Select-Object * -ExcludeProperty ETag
54+
$History = Get-CippAzDataTableEntity @HistoryTable -Filter $Filter -Property PartitionKey, RowKey, Timestamp, EventType, Name, IsPlayed, OrchestrationStatus | Select-Object * -ExcludeProperty ETag
5555

5656
$Body = [PSCustomObject]@{
5757
Results = @($History)
@@ -173,4 +173,4 @@ function Invoke-ExecDurableFunctions {
173173
StatusCode = [HttpStatusCode]::OK
174174
Body = $Body
175175
})
176-
}
176+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Extensions/Invoke-ExecExtensionsConfig.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Function Invoke-ExecExtensionsConfig {
5757
}
5858
}
5959
if ($Request.Body.$APIKey.PSObject.Properties -notcontains 'APIKey') {
60-
$Request.Body.$APIKey | Add-Member -MemberType NoteProperty -Name APIKey -Value 'SentToKeyVault' -PassThru
60+
$Request.Body.$APIKey | Add-Member -MemberType NoteProperty -Name APIKey -Value 'SentToKeyVault'
6161
} else {
6262
$Request.Body.$APIKey.APIKey = 'SentToKeyVault'
6363
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Function Invoke-AddGroupTemplate {
99
#>
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)
12-
1312
$APIName = $TriggerMetadata.FunctionName
1413
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1514

@@ -36,8 +35,7 @@ Function Invoke-AddGroupTemplate {
3635
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created Group template named $($Request.body.displayname) with GUID $GUID" -Sev 'Debug'
3736

3837
$body = [pscustomobject]@{'Results' = 'Successfully added template' }
39-
}
40-
catch {
38+
} catch {
4139
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Group Template Creation failed: $($_.Exception.Message)" -Sev 'Error'
4240
$body = [pscustomobject]@{'Results' = "Group Template Creation failed: $($_.Exception.Message)" }
4341
}

Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,55 @@ function Get-CIPPAzDataTableEntity {
1717
foreach ($entity in $Results) {
1818
if ($entity.OriginalEntityId) {
1919
$entityId = $entity.OriginalEntityId
20-
if (-not $mergedResults.ContainsKey($entityId)) {
21-
$mergedResults[$entityId] = @{
20+
$partitionKey = $entity.PartitionKey
21+
if (-not $mergedResults.ContainsKey($partitionKey)) {
22+
$mergedResults[$partitionKey] = @{}
23+
}
24+
if (-not $mergedResults[$partitionKey].ContainsKey($entityId)) {
25+
$mergedResults[$partitionKey][$entityId] = @{
2226
Parts = New-Object 'System.Collections.ArrayList'
2327
}
2428
}
25-
$mergedResults[$entityId]['Parts'].Add($entity) > $null
29+
$mergedResults[$partitionKey][$entityId]['Parts'].Add($entity) > $null
2630
} else {
27-
$mergedResults[$entity.RowKey] = @{
31+
$partitionKey = $entity.PartitionKey
32+
if (-not $mergedResults.ContainsKey($partitionKey)) {
33+
$mergedResults[$partitionKey] = @{}
34+
}
35+
$mergedResults[$partitionKey][$entity.RowKey] = @{
2836
Entity = $entity
2937
Parts = New-Object 'System.Collections.ArrayList'
3038
}
3139
}
3240
}
3341

34-
# Second pass: Reassemble entities from parts
3542
$finalResults = @()
36-
foreach ($entityId in $mergedResults.Keys) {
37-
$entityData = $mergedResults[$entityId]
38-
if ($entityData.Parts.Count -gt 0) {
39-
$fullEntity = [PSCustomObject]@{}
40-
$parts = $entityData.Parts | Sort-Object PartIndex
41-
foreach ($part in $parts) {
42-
foreach ($key in $part.PSObject.Properties.Name) {
43-
if ($key -notin @('OriginalEntityId', 'PartIndex', 'PartitionKey', 'RowKey', 'Timestamp')) {
44-
if ($fullEntity.PSObject.Properties[$key]) {
45-
$fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value ($fullEntity.$key + $part.$key) -Force
46-
} else {
47-
$fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value $part.$key
43+
foreach ($partitionKey in $mergedResults.Keys) {
44+
foreach ($entityId in $mergedResults[$partitionKey].Keys) {
45+
$entityData = $mergedResults[$partitionKey][$entityId]
46+
if ($entityData.Parts.Count -gt 0) {
47+
$fullEntity = [PSCustomObject]@{}
48+
$parts = $entityData.Parts | Sort-Object PartIndex
49+
foreach ($part in $parts) {
50+
foreach ($key in $part.PSObject.Properties.Name) {
51+
if ($key -notin @('OriginalEntityId', 'PartIndex', 'PartitionKey', 'RowKey', 'Timestamp')) {
52+
if ($fullEntity.PSObject.Properties[$key]) {
53+
$fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value ($fullEntity.$key + $part.$key) -Force
54+
} else {
55+
$fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value $part.$key
56+
}
4857
}
4958
}
5059
}
60+
$fullEntity | Add-Member -MemberType NoteProperty -Name 'PartitionKey' -Value $parts[0].PartitionKey -Force
61+
$fullEntity | Add-Member -MemberType NoteProperty -Name 'RowKey' -Value $entityId -Force
62+
$finalResults = $finalResults + @($fullEntity)
63+
} else {
64+
$finalResults = $finalResults + @($entityData.Entity)
5165
}
52-
$fullEntity | Add-Member -MemberType NoteProperty -Name 'PartitionKey' -Value $parts[0].PartitionKey -Force
53-
$fullEntity | Add-Member -MemberType NoteProperty -Name 'RowKey' -Value $entityId -Force
54-
$finalResults = $finalResults + @($fullEntity)
55-
} else {
56-
$finalResults = $finalResults + @($entityData.Entity)
5766
}
5867
}
5968

60-
# Third pass: Process split properties and remerge them
6169
foreach ($entity in $finalResults) {
6270
if ($entity.SplitOverProps) {
6371
$splitInfoList = $entity.SplitOverProps | ConvertFrom-Json

Modules/CIPPCore/Public/GraphHelper/New-ExoRequest.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ function New-ExoRequest ($tenantid, $cmdlet, $cmdParams, $useSystemMailbox, $Anc
2323
if ($cmdparams.anr) { $Anchor = $cmdparams.anr }
2424
if ($cmdparams.User) { $Anchor = $cmdparams.User }
2525
if ($cmdparams.mailbox) { $Anchor = $cmdparams.mailbox }
26-
if ($cmdlet -in 'Set-AdminAuditLogConfig', 'Get-AdminAuditLogConfig', 'Enable-OrganizationCustomization', 'Get-OrganizationConfig') { $anchor = "UPN:SystemMailbox{8cc370d3-822a-4ab8-a926-bb94bd0641a9}@$($OnMicrosoft)" }
2726
if (!$Anchor -or $useSystemMailbox) {
2827
if (!$Tenant.initialDomainName -or $Tenant.initialDomainName -notlike '*onmicrosoft.com*') {
2928
$OnMicrosoft = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/domains?$top=999' -tenantid $tenantid -NoAuthCheck $NoAuthCheck | Where-Object -Property isInitial -EQ $true).id
3029
} else {
3130
$OnMicrosoft = $Tenant.initialDomainName
3231
}
3332
$anchor = "UPN:SystemMailbox{bb558c35-97f1-4cb9-8ff7-d53741dc928c}@$($OnMicrosoft)"
33+
if ($cmdlet -in 'Set-AdminAuditLogConfig', 'Get-AdminAuditLogConfig', 'Enable-OrganizationCustomization', 'Get-OrganizationConfig') { $anchor = "UPN:SystemMailbox{8cc370d3-822a-4ab8-a926-bb94bd0641a9}@$($OnMicrosoft)" }
34+
3435
}
3536
#if the anchor is a GUID, try looking up the user.
3637
if ($Anchor -match '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$') {

Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ function Write-CippFunctionStats {
1111
[string]$ErrorMsg = ''
1212
)
1313
try {
14+
$Start = Get-Date $Start
15+
$End = Get-Date $End
16+
1417
$Table = Get-CIPPTable -tablename CippFunctionStats
1518
$RowKey = [string](New-Guid).Guid
1619
$TimeSpan = New-TimeSpan -Start $Start -End $End
1720
$Duration = [int]$TimeSpan.TotalSeconds
1821
$DurationMS = [int]$TimeSpan.TotalMilliseconds
1922

23+
# if datetime is local, convert to UTC
24+
if ($Start.Kind -eq 'Local') {
25+
$Start = $Start.ToUniversalTime()
26+
}
27+
if ($End.Kind -eq 'Local') {
28+
$End = $End.ToUniversalTime()
29+
}
30+
2031
$StatEntity = @{}
2132
# Flatten data to json string
2233
$StatEntity.PartitionKey = $FunctionType
@@ -28,13 +39,16 @@ function Write-CippFunctionStats {
2839
$StatEntity.ErrorMsg = $ErrorMsg
2940
$Entity = [PSCustomObject]$Entity
3041
foreach ($Property in $Entity.PSObject.Properties.Name) {
31-
if ($Entity.$Property.GetType().Name -in ('Hashtable', 'PSCustomObject', 'OrderedHashtable')) {
32-
$StatEntity.$Property = [string]($Entity.$Property | ConvertTo-Json -Compress)
33-
} elseif ($Property -notin ('ETag', 'RowKey', 'PartitionKey', 'Timestamp', 'LastRefresh')) {
34-
$StatEntity.$Property = $Entity.$Property
42+
if ($Entity.$Property) {
43+
if ($Entity.$Property.GetType().Name -in ('Hashtable', 'PSCustomObject', 'OrderedHashtable')) {
44+
$StatEntity.$Property = [string]($Entity.$Property | ConvertTo-Json -Compress)
45+
} elseif ($Property -notin ('ETag', 'RowKey', 'PartitionKey', 'Timestamp', 'LastRefresh')) {
46+
$StatEntity.$Property = $Entity.$Property
47+
}
3548
}
3649
}
3750
$StatEntity = [PSCustomObject]$StatEntity
51+
3852
Add-CIPPAzDataTableEntity @Table -Entity $StatEntity -Force
3953
} catch {
4054
Write-Host "Exception logging stats $($_.Exception.Message)"

Modules/CIPPCore/Public/Set-CIPPUserJITAdminProperties.ps1

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@ function Set-CIPPUserJITAdminProperties {
77
$Expiration,
88
[switch]$Clear
99
)
10-
11-
$Schema = Get-CIPPSchemaExtensions | Where-Object { $_.id -match '_cippUser' }
12-
if ($Clear.IsPresent) {
13-
$Body = [PSCustomObject]@{
14-
"$($Schema.id)" = @{
15-
jitAdminEnabled = $null
16-
jitAdminExpiration = $null
10+
try {
11+
$Schema = Get-CIPPSchemaExtensions | Where-Object { $_.id -match '_cippUser' }
12+
if ($Clear.IsPresent) {
13+
$Body = [PSCustomObject]@{
14+
"$($Schema.id)" = @{
15+
jitAdminEnabled = $null
16+
jitAdminExpiration = $null
17+
}
1718
}
18-
}
19-
} else {
20-
$Body = [PSCustomObject]@{
21-
"$($Schema.id)" = @{
22-
jitAdminEnabled = $Enabled.IsPresent
23-
jitAdminExpiration = $Expiration.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
19+
} else {
20+
$Body = [PSCustomObject]@{
21+
"$($Schema.id)" = @{
22+
jitAdminEnabled = $Enabled.IsPresent
23+
jitAdminExpiration = $Expiration.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
24+
}
2425
}
2526
}
26-
}
2727

28-
$Json = ConvertTo-Json -Depth 5 -InputObject $Body
29-
Write-Information $Json
30-
New-GraphPOSTRequest -type PATCH -Uri "https://graph.microsoft.com/beta/users/$UserId" -Body $Json -tenantid $TenantFilter | Out-Null
31-
}
28+
$Json = ConvertTo-Json -Depth 5 -InputObject $Body
29+
Write-Information $Json
30+
New-GraphPOSTRequest -type PATCH -Uri "https://graph.microsoft.com/beta/users/$UserId" -Body $Json -tenantid $TenantFilter | Out-Null
31+
} catch {
32+
Write-Information "Error setting JIT Admin properties: $($_.Exception.Message) - $($_.InvocationInfo.PositionMessage)"
33+
}
34+
}

Modules/CippEntrypoints/CippEntrypoints.psm1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ function Receive-CippHttpTrigger {
99
$Request,
1010
$TriggerMetadata
1111
)
12-
12+
# Convert the request to a PSCustomObject because the httpContext is case sensitive since 7.3
13+
$Request = $Request | ConvertTo-Json -Depth 100 | ConvertFrom-Json
1314
Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName
1415
$FunctionName = 'Invoke-{0}' -f $Request.Params.CIPPEndpoint
1516
Write-Host "Function: $($Request.Params.CIPPEndpoint)"
1617

1718
$HttpTrigger = @{
18-
Request = $Request
19+
Request = [pscustomobject]($Request)
1920
TriggerMetadata = $TriggerMetadata
2021
}
2122

@@ -43,6 +44,7 @@ function Receive-CippHttpTrigger {
4344

4445
function Receive-CippQueueTrigger {
4546
Param($QueueItem, $TriggerMetadata)
47+
4648
Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName
4749
$Start = (Get-Date).ToUniversalTime()
4850
$APIName = $TriggerMetadata.FunctionName
@@ -144,7 +146,7 @@ function Receive-CippOrchestrationTrigger {
144146
function Receive-CippActivityTrigger {
145147
Param($Item)
146148
try {
147-
$Start = (Get-Date).ToUniversalTime()
149+
$Start = Get-Date
148150
Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName
149151

150152
if ($Item.QueueId) {
@@ -188,7 +190,7 @@ function Receive-CippActivityTrigger {
188190
}
189191
}
190192

191-
$End = (Get-Date).ToUniversalTime()
193+
$End = Get-Date
192194

193195
try {
194196
$Stats = @{

0 commit comments

Comments
 (0)