From 75f24159b7654eda70c121e7174c24ac8ee62959 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Wed, 10 Jul 2024 21:54:52 -0400 Subject: [PATCH 01/15] Update Invoke-ExecExtensionsConfig.ps1 --- .../CIPP/Extensions/Invoke-ExecExtensionsConfig.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Extensions/Invoke-ExecExtensionsConfig.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Extensions/Invoke-ExecExtensionsConfig.ps1 index 0e7ec5f6754c..2484fd9885dd 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Extensions/Invoke-ExecExtensionsConfig.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Extensions/Invoke-ExecExtensionsConfig.ps1 @@ -57,7 +57,7 @@ Function Invoke-ExecExtensionsConfig { } } if ($Request.Body.$APIKey.PSObject.Properties -notcontains 'APIKey') { - $Request.Body.$APIKey | Add-Member -MemberType NoteProperty -Name APIKey -Value 'SentToKeyVault' -PassThru + $Request.Body.$APIKey | Add-Member -MemberType NoteProperty -Name APIKey -Value 'SentToKeyVault' } else { $Request.Body.$APIKey.APIKey = 'SentToKeyVault' } From d25a26a0df0850a0d75d570e4f391500d4caec9d Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 17:09:37 +0200 Subject: [PATCH 02/15] fixes weird partition key spread --- .../Public/Get-CIPPAzDatatableEntity.ps1 | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1 b/Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1 index 60ee9464ab93..fd5676683860 100644 --- a/Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1 +++ b/Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1 @@ -17,47 +17,55 @@ function Get-CIPPAzDataTableEntity { foreach ($entity in $Results) { if ($entity.OriginalEntityId) { $entityId = $entity.OriginalEntityId - if (-not $mergedResults.ContainsKey($entityId)) { - $mergedResults[$entityId] = @{ + $partitionKey = $entity.PartitionKey + if (-not $mergedResults.ContainsKey($partitionKey)) { + $mergedResults[$partitionKey] = @{} + } + if (-not $mergedResults[$partitionKey].ContainsKey($entityId)) { + $mergedResults[$partitionKey][$entityId] = @{ Parts = New-Object 'System.Collections.ArrayList' } } - $mergedResults[$entityId]['Parts'].Add($entity) > $null + $mergedResults[$partitionKey][$entityId]['Parts'].Add($entity) > $null } else { - $mergedResults[$entity.RowKey] = @{ + $partitionKey = $entity.PartitionKey + if (-not $mergedResults.ContainsKey($partitionKey)) { + $mergedResults[$partitionKey] = @{} + } + $mergedResults[$partitionKey][$entity.RowKey] = @{ Entity = $entity Parts = New-Object 'System.Collections.ArrayList' } } } - # Second pass: Reassemble entities from parts $finalResults = @() - foreach ($entityId in $mergedResults.Keys) { - $entityData = $mergedResults[$entityId] - if ($entityData.Parts.Count -gt 0) { - $fullEntity = [PSCustomObject]@{} - $parts = $entityData.Parts | Sort-Object PartIndex - foreach ($part in $parts) { - foreach ($key in $part.PSObject.Properties.Name) { - if ($key -notin @('OriginalEntityId', 'PartIndex', 'PartitionKey', 'RowKey', 'Timestamp')) { - if ($fullEntity.PSObject.Properties[$key]) { - $fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value ($fullEntity.$key + $part.$key) -Force - } else { - $fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value $part.$key + foreach ($partitionKey in $mergedResults.Keys) { + foreach ($entityId in $mergedResults[$partitionKey].Keys) { + $entityData = $mergedResults[$partitionKey][$entityId] + if ($entityData.Parts.Count -gt 0) { + $fullEntity = [PSCustomObject]@{} + $parts = $entityData.Parts | Sort-Object PartIndex + foreach ($part in $parts) { + foreach ($key in $part.PSObject.Properties.Name) { + if ($key -notin @('OriginalEntityId', 'PartIndex', 'PartitionKey', 'RowKey', 'Timestamp')) { + if ($fullEntity.PSObject.Properties[$key]) { + $fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value ($fullEntity.$key + $part.$key) -Force + } else { + $fullEntity | Add-Member -MemberType NoteProperty -Name $key -Value $part.$key + } } } } + $fullEntity | Add-Member -MemberType NoteProperty -Name 'PartitionKey' -Value $parts[0].PartitionKey -Force + $fullEntity | Add-Member -MemberType NoteProperty -Name 'RowKey' -Value $entityId -Force + $finalResults = $finalResults + @($fullEntity) + } else { + $finalResults = $finalResults + @($entityData.Entity) } - $fullEntity | Add-Member -MemberType NoteProperty -Name 'PartitionKey' -Value $parts[0].PartitionKey -Force - $fullEntity | Add-Member -MemberType NoteProperty -Name 'RowKey' -Value $entityId -Force - $finalResults = $finalResults + @($fullEntity) - } else { - $finalResults = $finalResults + @($entityData.Entity) } } - # Third pass: Process split properties and remerge them foreach ($entity in $finalResults) { if ($entity.SplitOverProps) { $splitInfoList = $entity.SplitOverProps | ConvertFrom-Json From 9b80cd13eb35c78a592a17e37b01262e6c6ddc27 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 17:24:20 +0200 Subject: [PATCH 03/15] exo request mistake --- Modules/CIPPCore/Public/GraphHelper/New-ExoRequest.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/GraphHelper/New-ExoRequest.ps1 b/Modules/CIPPCore/Public/GraphHelper/New-ExoRequest.ps1 index da4240415e6e..1217dc4886e6 100644 --- a/Modules/CIPPCore/Public/GraphHelper/New-ExoRequest.ps1 +++ b/Modules/CIPPCore/Public/GraphHelper/New-ExoRequest.ps1 @@ -23,7 +23,6 @@ function New-ExoRequest ($tenantid, $cmdlet, $cmdParams, $useSystemMailbox, $Anc if ($cmdparams.anr) { $Anchor = $cmdparams.anr } if ($cmdparams.User) { $Anchor = $cmdparams.User } if ($cmdparams.mailbox) { $Anchor = $cmdparams.mailbox } - if ($cmdlet -in 'Set-AdminAuditLogConfig', 'Get-AdminAuditLogConfig', 'Enable-OrganizationCustomization', 'Get-OrganizationConfig') { $anchor = "UPN:SystemMailbox{8cc370d3-822a-4ab8-a926-bb94bd0641a9}@$($OnMicrosoft)" } if (!$Anchor -or $useSystemMailbox) { if (!$Tenant.initialDomainName -or $Tenant.initialDomainName -notlike '*onmicrosoft.com*') { $OnMicrosoft = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/domains?$top=999' -tenantid $tenantid -NoAuthCheck $NoAuthCheck | Where-Object -Property isInitial -EQ $true).id @@ -31,6 +30,8 @@ function New-ExoRequest ($tenantid, $cmdlet, $cmdParams, $useSystemMailbox, $Anc $OnMicrosoft = $Tenant.initialDomainName } $anchor = "UPN:SystemMailbox{bb558c35-97f1-4cb9-8ff7-d53741dc928c}@$($OnMicrosoft)" + if ($cmdlet -in 'Set-AdminAuditLogConfig', 'Get-AdminAuditLogConfig', 'Enable-OrganizationCustomization', 'Get-OrganizationConfig') { $anchor = "UPN:SystemMailbox{8cc370d3-822a-4ab8-a926-bb94bd0641a9}@$($OnMicrosoft)" } + } #if the anchor is a GUID, try looking up the user. if ($Anchor -match '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$') { From 4a4b29d1d5979949148d2e4f9cf28ae3f4ede7e8 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 17:26:38 +0200 Subject: [PATCH 04/15] fixes scheduler --- Scheduler_UserTasks/function.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scheduler_UserTasks/function.json b/Scheduler_UserTasks/function.json index 017acb166958..f7af84092121 100644 --- a/Scheduler_UserTasks/function.json +++ b/Scheduler_UserTasks/function.json @@ -2,7 +2,7 @@ "bindings": [ { "name": "Timer", - "schedule": "0 */5 * * * *", + "schedule": "0 */15 * * * *", "direction": "in", "type": "timerTrigger" }, From d078a94b0496c5947b0d9a9f2bf278a864bb60a9 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Thu, 11 Jul 2024 13:48:51 -0400 Subject: [PATCH 05/15] Fix stats logging Add queue entry for scheduled tasks Fix missing partitionkeys --- .../Domain Analyser/Push-GetTenantDomains.ps1 | 4 ++-- .../Push-GetPendingWebhooks.ps1 | 4 ++-- .../CIPP/Core/Invoke-ExecDurableFunctions.ps1 | 4 ++-- .../GraphHelper/Write-CippFunctionStats.ps1 | 22 +++++++++++++++---- Modules/CippEntrypoints/CippEntrypoints.psm1 | 4 ++-- Scheduler_GetWebhooks/run.ps1 | 2 +- Scheduler_UserTasks/run.ps1 | 7 +++++- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 index 5fb9c64cdad1..071bb5289139 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 @@ -2,6 +2,6 @@ function Push-GetTenantDomains { Param($Item) $DomainTable = Get-CippTable -tablename 'Domains' $Filter = "PartitionKey eq 'TenantDomains' and TenantGUID eq '{0}'" -f $Item.TenantGUID - $Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter -Property RowKey | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } } + $Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter -Property PartitionKey, RowKey | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } } return @($Domains) -} \ No newline at end of file +} diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-GetPendingWebhooks.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-GetPendingWebhooks.ps1 index 4b292fdd7041..2cdf56c8a6b5 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-GetPendingWebhooks.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-GetPendingWebhooks.ps1 @@ -5,9 +5,9 @@ function Push-GetPendingWebhooks { #> Param($Item) $Table = Get-CIPPTable -TableName WebhookIncoming - $Webhooks = Get-CIPPAzDataTableEntity @Table -Property RowKey, FunctionName -First 10000 + $Webhooks = Get-CIPPAzDataTableEntity @Table -Property PartitionKey, RowKey, FunctionName -First 10000 $WebhookCount = ($Webhooks | Measure-Object).Count $Message = 'Processing {0} webhooks' -f $WebhookCount Write-LogMessage -API 'Webhooks' -message $Message -sev Info return $Webhooks -} \ No newline at end of file +} diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecDurableFunctions.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecDurableFunctions.ps1 index 09da6bd2c990..f01062fe5720 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecDurableFunctions.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecDurableFunctions.ps1 @@ -51,7 +51,7 @@ function Invoke-ExecDurableFunctions { if ($Request.Query.PartitionKey) { $HistoryTable = Get-CippTable -TableName ('{0}History' -f $FunctionName) $Filter = "PartitionKey eq '{0}'" -f $Request.Query.PartitionKey - $History = Get-CippAzDataTableEntity @HistoryTable -Filter $Filter -Property RowKey, Timestamp, EventType, Name, IsPlayed, OrchestrationStatus | Select-Object * -ExcludeProperty ETag + $History = Get-CippAzDataTableEntity @HistoryTable -Filter $Filter -Property PartitionKey, RowKey, Timestamp, EventType, Name, IsPlayed, OrchestrationStatus | Select-Object * -ExcludeProperty ETag $Body = [PSCustomObject]@{ Results = @($History) @@ -173,4 +173,4 @@ function Invoke-ExecDurableFunctions { StatusCode = [HttpStatusCode]::OK Body = $Body }) -} \ No newline at end of file +} diff --git a/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 b/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 index f73051f931a6..c213c74cfaa4 100644 --- a/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 +++ b/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 @@ -11,12 +11,23 @@ function Write-CippFunctionStats { [string]$ErrorMsg = '' ) try { + $Start = Get-Date $Start + $End = Get-Date $End + $Table = Get-CIPPTable -tablename CippFunctionStats $RowKey = [string](New-Guid).Guid $TimeSpan = New-TimeSpan -Start $Start -End $End $Duration = [int]$TimeSpan.TotalSeconds $DurationMS = [int]$TimeSpan.TotalMilliseconds + # if datetime is local, convert to UTC + if ($Start.Kind -eq 'Local') { + $Start = $Start.ToUniversalTime() + } + if ($End.Kind -eq 'Local') { + $End = $End.ToUniversalTime() + } + $StatEntity = @{} # Flatten data to json string $StatEntity.PartitionKey = $FunctionType @@ -28,13 +39,16 @@ function Write-CippFunctionStats { $StatEntity.ErrorMsg = $ErrorMsg $Entity = [PSCustomObject]$Entity foreach ($Property in $Entity.PSObject.Properties.Name) { - if ($Entity.$Property.GetType().Name -in ('Hashtable', 'PSCustomObject', 'OrderedHashtable')) { - $StatEntity.$Property = [string]($Entity.$Property | ConvertTo-Json -Compress) - } elseif ($Property -notin ('ETag', 'RowKey', 'PartitionKey', 'Timestamp', 'LastRefresh')) { - $StatEntity.$Property = $Entity.$Property + if ($Entity.$Property) { + if ($Entity.$Property.GetType().Name -in ('Hashtable', 'PSCustomObject', 'OrderedHashtable')) { + $StatEntity.$Property = [string]($Entity.$Property | ConvertTo-Json -Compress) + } elseif ($Property -notin ('ETag', 'RowKey', 'PartitionKey', 'Timestamp', 'LastRefresh')) { + $StatEntity.$Property = $Entity.$Property + } } } $StatEntity = [PSCustomObject]$StatEntity + Write-Information ($StatEntity | ConvertTo-Json -Compress) Add-CIPPAzDataTableEntity @Table -Entity $StatEntity -Force } catch { Write-Host "Exception logging stats $($_.Exception.Message)" diff --git a/Modules/CippEntrypoints/CippEntrypoints.psm1 b/Modules/CippEntrypoints/CippEntrypoints.psm1 index 994dab0633bf..3f014014f0da 100644 --- a/Modules/CippEntrypoints/CippEntrypoints.psm1 +++ b/Modules/CippEntrypoints/CippEntrypoints.psm1 @@ -144,7 +144,7 @@ function Receive-CippOrchestrationTrigger { function Receive-CippActivityTrigger { Param($Item) try { - $Start = (Get-Date).ToUniversalTime() + $Start = Get-Date Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName if ($Item.QueueId) { @@ -188,7 +188,7 @@ function Receive-CippActivityTrigger { } } - $End = (Get-Date).ToUniversalTime() + $End = Get-Date try { $Stats = @{ diff --git a/Scheduler_GetWebhooks/run.ps1 b/Scheduler_GetWebhooks/run.ps1 index 3eb4aaae42fd..cef8cfb6d726 100644 --- a/Scheduler_GetWebhooks/run.ps1 +++ b/Scheduler_GetWebhooks/run.ps1 @@ -3,7 +3,7 @@ param($Timer) try { $webhookTable = Get-CIPPTable -tablename webhookTable - $Webhooks = Get-CIPPAzDataTableEntity @webhookTable -Property RowKey + $Webhooks = Get-CIPPAzDataTableEntity @webhookTable -Property PartitionKey, RowKey if (($Webhooks | Measure-Object).Count -eq 0) { Write-Host 'No webhook subscriptions found. Exiting.' return diff --git a/Scheduler_UserTasks/run.ps1 b/Scheduler_UserTasks/run.ps1 index b5d5cdd874ca..950ca9e691bb 100644 --- a/Scheduler_UserTasks/run.ps1 +++ b/Scheduler_UserTasks/run.ps1 @@ -57,6 +57,11 @@ foreach ($task in $tasks) { } } if (($Batch | Measure-Object).Count -gt 0) { + # Create queue entry + $Queue = New-CippQueueEntry -Name 'Scheduled Tasks' -TotalTasks ($Batch | Measure-Object).Count + $QueueId = $Queue.RowKey + $Batch = $Batch | Select-Object *, @{Name = 'QueueId'; Expression = { $QueueId } }, @{Name = 'QueueName'; Expression = { '{0} - {1}' -f $_.TaskInfo.Name, ($_.TaskInfo.Tenant -ne 'AllTenants' ? $_.TaskInfo.Tenant : $_.Parameters.TenantFilter) } } + $InputObject = [PSCustomObject]@{ OrchestratorName = 'UserTaskOrchestrator' Batch = @($Batch) @@ -66,4 +71,4 @@ if (($Batch | Measure-Object).Count -gt 0) { $InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 10 -Compress) Write-Host "Started orchestration with ID = '$InstanceId'" -} \ No newline at end of file +} From f5b4a23524cd61206b316dc6d4c89324089891e3 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 19:49:53 +0200 Subject: [PATCH 06/15] test --- .../Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 index 83d8e9a64743..ddd669945b9f 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 @@ -15,7 +15,7 @@ Function Invoke-AddGroupTemplate { $GUID = (New-Guid).GUID try { - if (!$Request.body.displayname) { throw 'You must enter a displayname' } + if (!$Request.body.displayName) { throw 'You must enter a displayname' } $object = [PSCustomObject]@{ Displayname = $request.body.displayname From 13888dd3b9234d172bc7315ea4fe0c7abb791239 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 20:01:34 +0200 Subject: [PATCH 07/15] test --- .../Administration/Groups/Invoke-AddGroupTemplate.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 index ddd669945b9f..d877cb0a7fd6 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 @@ -9,13 +9,13 @@ Function Invoke-AddGroupTemplate { #> [CmdletBinding()] param($Request, $TriggerMetadata) - + $request | ConvertTo-Json -depth 100 | ConvertFrom-Json $APIName = $TriggerMetadata.FunctionName Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' $GUID = (New-Guid).GUID try { - if (!$Request.body.displayName) { throw 'You must enter a displayname' } + if (!$Request.body.displayname) { throw 'You must enter a displayname' } $object = [PSCustomObject]@{ Displayname = $request.body.displayname @@ -36,8 +36,7 @@ Function Invoke-AddGroupTemplate { Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created Group template named $($Request.body.displayname) with GUID $GUID" -Sev 'Debug' $body = [pscustomobject]@{'Results' = 'Successfully added template' } - } - catch { + } catch { Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Group Template Creation failed: $($_.Exception.Message)" -Sev 'Error' $body = [pscustomobject]@{'Results' = "Group Template Creation failed: $($_.Exception.Message)" } } From 2057ba6525ba85dd26a0f717bfe7c3cf5b18b9a6 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 20:05:23 +0200 Subject: [PATCH 08/15] test --- .../Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 index d877cb0a7fd6..b4a6207bcb94 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 @@ -9,7 +9,7 @@ Function Invoke-AddGroupTemplate { #> [CmdletBinding()] param($Request, $TriggerMetadata) - $request | ConvertTo-Json -depth 100 | ConvertFrom-Json + $Request = $Request | ConvertTo-Json -Depth 100 | ConvertFrom-Json $APIName = $TriggerMetadata.FunctionName Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' From 2b7d3fd5ebe5b487ed6308e3cd52e31fee8a8d4b Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 20:12:41 +0200 Subject: [PATCH 09/15] set as pscustomobj --- .../Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 index b4a6207bcb94..79957f39d558 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 @@ -9,7 +9,7 @@ Function Invoke-AddGroupTemplate { #> [CmdletBinding()] param($Request, $TriggerMetadata) - $Request = $Request | ConvertTo-Json -Depth 100 | ConvertFrom-Json + $Request = [pscustomobject]($Request) $APIName = $TriggerMetadata.FunctionName Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' From cf7aec9c0103f6c3cef9a614ccd17ae19c9d89da Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 20:18:08 +0200 Subject: [PATCH 10/15] force change to function input --- .../Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 | 1 - Modules/CippEntrypoints/CippEntrypoints.psm1 | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 index 79957f39d558..6574633a16c7 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1 @@ -9,7 +9,6 @@ Function Invoke-AddGroupTemplate { #> [CmdletBinding()] param($Request, $TriggerMetadata) - $Request = [pscustomobject]($Request) $APIName = $TriggerMetadata.FunctionName Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' diff --git a/Modules/CippEntrypoints/CippEntrypoints.psm1 b/Modules/CippEntrypoints/CippEntrypoints.psm1 index 994dab0633bf..1ab0772bb996 100644 --- a/Modules/CippEntrypoints/CippEntrypoints.psm1 +++ b/Modules/CippEntrypoints/CippEntrypoints.psm1 @@ -9,7 +9,7 @@ function Receive-CippHttpTrigger { $Request, $TriggerMetadata ) - + $Request = [pscustomobject]($Request) Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName $FunctionName = 'Invoke-{0}' -f $Request.Params.CIPPEndpoint Write-Host "Function: $($Request.Params.CIPPEndpoint)" @@ -43,6 +43,7 @@ function Receive-CippHttpTrigger { function Receive-CippQueueTrigger { Param($QueueItem, $TriggerMetadata) + Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName $Start = (Get-Date).ToUniversalTime() $APIName = $TriggerMetadata.FunctionName From adc89c7456ae2e4b0c2579f7d88de3a02d1789eb Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 20:21:41 +0200 Subject: [PATCH 11/15] object --- Modules/CippEntrypoints/CippEntrypoints.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CippEntrypoints/CippEntrypoints.psm1 b/Modules/CippEntrypoints/CippEntrypoints.psm1 index 1ab0772bb996..0687a41e3d87 100644 --- a/Modules/CippEntrypoints/CippEntrypoints.psm1 +++ b/Modules/CippEntrypoints/CippEntrypoints.psm1 @@ -15,7 +15,7 @@ function Receive-CippHttpTrigger { Write-Host "Function: $($Request.Params.CIPPEndpoint)" $HttpTrigger = @{ - Request = $Request + Request = [pscustomobject]($Request) TriggerMetadata = $TriggerMetadata } From 9c34d00f8cfb9f8a96331cca0caf7d5cb3037e24 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 20:27:31 +0200 Subject: [PATCH 12/15] test --- Modules/CippEntrypoints/CippEntrypoints.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/CippEntrypoints/CippEntrypoints.psm1 b/Modules/CippEntrypoints/CippEntrypoints.psm1 index 0687a41e3d87..1bba756aaf83 100644 --- a/Modules/CippEntrypoints/CippEntrypoints.psm1 +++ b/Modules/CippEntrypoints/CippEntrypoints.psm1 @@ -10,6 +10,7 @@ function Receive-CippHttpTrigger { $TriggerMetadata ) $Request = [pscustomobject]($Request) + Write-Host "$Request is a: $($Request.GetType().Name)" Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName $FunctionName = 'Invoke-{0}' -f $Request.Params.CIPPEndpoint Write-Host "Function: $($Request.Params.CIPPEndpoint)" From ffd5bc5d15efbca3e4d8c4374cfd38a34fdf151c Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Thu, 11 Jul 2024 20:32:53 +0200 Subject: [PATCH 13/15] convert --- Modules/CippEntrypoints/CippEntrypoints.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/CippEntrypoints/CippEntrypoints.psm1 b/Modules/CippEntrypoints/CippEntrypoints.psm1 index 1bba756aaf83..77732af547b5 100644 --- a/Modules/CippEntrypoints/CippEntrypoints.psm1 +++ b/Modules/CippEntrypoints/CippEntrypoints.psm1 @@ -9,8 +9,8 @@ function Receive-CippHttpTrigger { $Request, $TriggerMetadata ) - $Request = [pscustomobject]($Request) - Write-Host "$Request is a: $($Request.GetType().Name)" + # Convert the request to a PSCustomObject because the httpContext is case sensitive since 7.3 + $Request = $Request | ConvertTo-Json -Depth 100 | ConvertFrom-Json Set-Location (Get-Item $PSScriptRoot).Parent.Parent.FullName $FunctionName = 'Invoke-{0}' -f $Request.Params.CIPPEndpoint Write-Host "Function: $($Request.Params.CIPPEndpoint)" From da3a5aeb228d0d8cf6d61f1981dc17791e65a47e Mon Sep 17 00:00:00 2001 From: John Duprey Date: Thu, 11 Jul 2024 15:47:30 -0400 Subject: [PATCH 14/15] JIT tweaks --- .../GraphHelper/Write-CippFunctionStats.ps1 | 2 +- .../Public/Set-CIPPUserJITAdminProperties.ps1 | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 b/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 index c213c74cfaa4..0e295e96cc46 100644 --- a/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 +++ b/Modules/CIPPCore/Public/GraphHelper/Write-CippFunctionStats.ps1 @@ -48,7 +48,7 @@ function Write-CippFunctionStats { } } $StatEntity = [PSCustomObject]$StatEntity - Write-Information ($StatEntity | ConvertTo-Json -Compress) + Add-CIPPAzDataTableEntity @Table -Entity $StatEntity -Force } catch { Write-Host "Exception logging stats $($_.Exception.Message)" diff --git a/Modules/CIPPCore/Public/Set-CIPPUserJITAdminProperties.ps1 b/Modules/CIPPCore/Public/Set-CIPPUserJITAdminProperties.ps1 index c6203128f2f9..d9d3dfb8c9af 100644 --- a/Modules/CIPPCore/Public/Set-CIPPUserJITAdminProperties.ps1 +++ b/Modules/CIPPCore/Public/Set-CIPPUserJITAdminProperties.ps1 @@ -7,25 +7,28 @@ function Set-CIPPUserJITAdminProperties { $Expiration, [switch]$Clear ) - - $Schema = Get-CIPPSchemaExtensions | Where-Object { $_.id -match '_cippUser' } - if ($Clear.IsPresent) { - $Body = [PSCustomObject]@{ - "$($Schema.id)" = @{ - jitAdminEnabled = $null - jitAdminExpiration = $null + try { + $Schema = Get-CIPPSchemaExtensions | Where-Object { $_.id -match '_cippUser' } + if ($Clear.IsPresent) { + $Body = [PSCustomObject]@{ + "$($Schema.id)" = @{ + jitAdminEnabled = $null + jitAdminExpiration = $null + } } - } - } else { - $Body = [PSCustomObject]@{ - "$($Schema.id)" = @{ - jitAdminEnabled = $Enabled.IsPresent - jitAdminExpiration = $Expiration.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') + } else { + $Body = [PSCustomObject]@{ + "$($Schema.id)" = @{ + jitAdminEnabled = $Enabled.IsPresent + jitAdminExpiration = $Expiration.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') + } } } - } - $Json = ConvertTo-Json -Depth 5 -InputObject $Body - Write-Information $Json - New-GraphPOSTRequest -type PATCH -Uri "https://graph.microsoft.com/beta/users/$UserId" -Body $Json -tenantid $TenantFilter | Out-Null -} \ No newline at end of file + $Json = ConvertTo-Json -Depth 5 -InputObject $Body + Write-Information $Json + New-GraphPOSTRequest -type PATCH -Uri "https://graph.microsoft.com/beta/users/$UserId" -Body $Json -tenantid $TenantFilter | Out-Null + } catch { + Write-Information "Error setting JIT Admin properties: $($_.Exception.Message) - $($_.InvocationInfo.PositionMessage)" + } +} From 4c5059da5c098113fc02457c2a3558106e5e8b7e Mon Sep 17 00:00:00 2001 From: John Duprey Date: Thu, 11 Jul 2024 16:56:40 -0400 Subject: [PATCH 15/15] Update version_latest.txt --- version_latest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version_latest.txt b/version_latest.txt index 9b9a244206f6..090ea9dad19f 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -6.0.2 +6.0.3