From 590620c079950edd595158a1b7b688baa80ba779 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Mon, 29 Apr 2024 13:41:40 +0200 Subject: [PATCH 01/10] fix log entry --- .../CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 index 414de1edb6e7..32b979fa9c3c 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 @@ -12,13 +12,17 @@ Function Invoke-RemoveScheduledItem { RowKey = $Request.Query.ID PartitionKey = 'ScheduledTask' } + + $Table = Get-CIPPTable -TableName 'ScheduledTasks' Remove-AzDataTableEntity @Table -Entity $task + + Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Task removed: $($task.name)" -Sev 'Debug' + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ StatusCode = [HttpStatusCode]::OK Body = @{ Results = 'Task removed successfully.' } }) - Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Task removed' -Sev 'Debug' } From 8f9be7c2a0434c9791adcf9390be1b510a8b5cd0 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Mon, 29 Apr 2024 13:41:58 +0200 Subject: [PATCH 02/10] set severity --- .../CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 index 32b979fa9c3c..b76b8943182a 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 @@ -17,7 +17,7 @@ Function Invoke-RemoveScheduledItem { $Table = Get-CIPPTable -TableName 'ScheduledTasks' Remove-AzDataTableEntity @Table -Entity $task - Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Task removed: $($task.name)" -Sev 'Debug' + Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Task removed: $($task.name)" -Sev 'Info' Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ StatusCode = [HttpStatusCode]::OK From bcdc224af274ba20b49011ef26ddb6ec0ce3bbe7 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Mon, 29 Apr 2024 13:44:18 +0200 Subject: [PATCH 03/10] log entry clean up --- Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1 b/Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1 index 8cd5b159d458..952e3a68bc93 100644 --- a/Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1 +++ b/Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1 @@ -54,5 +54,5 @@ function Add-CIPPScheduledTask { } catch { return "Could not add task: $($_.Exception.Message)" } - return 'Successfully added task' + return "Successfully added task: $($entity.Name)" } \ No newline at end of file From 4a2fd76fcbd594d58b13010a939173ae48c7f949 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Mon, 29 Apr 2024 14:19:26 +0200 Subject: [PATCH 04/10] casing fix and logging --- .../Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 | 1 + .../CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 index 8321209ac94c..ff9efd329409 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 @@ -4,6 +4,7 @@ function Push-ExecScheduledCommand { Entrypoint #> param($Item) + Write-Host "We are going to be running a scheduled task: $($Item.TaskInfo | ConvertTo-Json)" $Table = Get-CippTable -tablename 'ScheduledTasks' $task = $Item.TaskInfo diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 index b76b8943182a..629760a2ca68 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-RemoveScheduledItem.ps1 @@ -17,7 +17,7 @@ Function Invoke-RemoveScheduledItem { $Table = Get-CIPPTable -TableName 'ScheduledTasks' Remove-AzDataTableEntity @Table -Entity $task - Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Task removed: $($task.name)" -Sev 'Info' + Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Task removed: $($task.Name)" -Sev 'Info' Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ StatusCode = [HttpStatusCode]::OK From 20acd6c7b13992f1df077e6b7eca2d12bfadfe4a Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Mon, 29 Apr 2024 14:41:12 +0200 Subject: [PATCH 05/10] text corrections --- .../Activity Triggers/Push-ExecScheduledCommand.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 index ff9efd329409..0b7f15b74e40 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 @@ -17,7 +17,6 @@ function Push-ExecScheduledCommand { $results = & $Item.command @commandParameters } catch { $results = "Task Failed: $($_.Exception.Message)" - } Write-Host 'ran the command' @@ -50,7 +49,7 @@ function Push-ExecScheduledCommand { $TableDesign = '' $HTML = ($results | Select-Object * -ExcludeProperty RowKey, PartitionKey | ConvertTo-Html -Fragment) -replace '', "$TableDesign
" | Out-String - $title = "Scheduled Task $($task.Name) - $($task.ExpectedRunTime)" + $title = "Scheduled Task $($task.Name)" Write-Host $title switch -wildcard ($task.PostExecution) { '*psa*' { Send-CIPPAlert -Type 'psa' -Title $title -HTMLContent $HTML } @@ -85,5 +84,5 @@ function Push-ExecScheduledCommand { ScheduledTime = "$nextRunUnixTime" } } - Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.name)" -sev Info + Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info } \ No newline at end of file From 0b0ee23aedd04d7866b8ed3eac4ee147131b068f Mon Sep 17 00:00:00 2001 From: John Duprey Date: Mon, 29 Apr 2024 08:58:04 -0400 Subject: [PATCH 06/10] fix domain analyser when tenant selector is empty --- Modules/CIPPCore/Public/Get-CIPPDomainAnalyser.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Get-CIPPDomainAnalyser.ps1 b/Modules/CIPPCore/Public/Get-CIPPDomainAnalyser.ps1 index 33aa626e7c88..0bc50c4acaad 100644 --- a/Modules/CIPPCore/Public/Get-CIPPDomainAnalyser.ps1 +++ b/Modules/CIPPCore/Public/Get-CIPPDomainAnalyser.ps1 @@ -18,7 +18,7 @@ function Get-CIPPDomainAnalyser { # Get all the things - if ($TenantFilter -ne 'AllTenants') { + if ($TenantFilter -ne 'AllTenants' -and ![string]::IsNullOrEmpty($TenantFilter)) { $DomainTable.Filter = "TenantGUID eq '{0}'" -f $TenantFilter } From a8ded0a96a621e140af965b2dd38be0c1debcfcb Mon Sep 17 00:00:00 2001 From: John Duprey Date: Mon, 29 Apr 2024 10:31:47 -0400 Subject: [PATCH 07/10] Fix scheduled tasks --- .../Push-ExecScheduledCommand.ps1 | 16 ++++++++++------ Modules/CIPPCore/Public/Set-CIPPSignInState.ps1 | 5 ++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 index 8321209ac94c..7c212e82cb47 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 @@ -7,13 +7,13 @@ function Push-ExecScheduledCommand { $Table = Get-CippTable -tablename 'ScheduledTasks' $task = $Item.TaskInfo - $commandParameters = $Item.Parameters + $commandParameters = $Item.Parameters | ConvertTo-Json | ConvertFrom-Json -AsHashtable $tenant = $Item.Parameters['TenantFilter'] - Write-Host 'started task' + Write-Host "Started Task: $($Item.Command) for tenant: $tenant" try { try { - $results = & $Item.command @commandParameters + $results = & $Item.Command @commandParameters } catch { $results = "Task Failed: $($_.Exception.Message)" @@ -28,9 +28,13 @@ function Push-ExecScheduledCommand { $results = $results | ForEach-Object { @{ Results = $_ } } } - $results = $results | Select-Object * -ExcludeProperty RowKey, PartitionKey + if ($results -is [string]) { + $StoredResults = $results + } else { + $results = $results | Select-Object * -ExcludeProperty RowKey, PartitionKey + $StoredResults = $results | ConvertTo-Json -Compress -Depth 20 | Out-String + } - $StoredResults = $results | ConvertTo-Json -Compress -Depth 20 | Out-String if ($StoredResults.Length -gt 64000 -or $task.Tenant -eq 'AllTenants') { $StoredResults = @{ Results = 'The results for this query are too long to store in this table, or the query was meant for All Tenants. Please use the options to send the results to another target to be able to view the results. ' } | ConvertTo-Json -Compress } @@ -84,5 +88,5 @@ function Push-ExecScheduledCommand { ScheduledTime = "$nextRunUnixTime" } } - Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.name)" -sev Info + Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info } \ No newline at end of file diff --git a/Modules/CIPPCore/Public/Set-CIPPSignInState.ps1 b/Modules/CIPPCore/Public/Set-CIPPSignInState.ps1 index 926d97aa90d6..ea26d3d309ed 100644 --- a/Modules/CIPPCore/Public/Set-CIPPSignInState.ps1 +++ b/Modules/CIPPCore/Public/Set-CIPPSignInState.ps1 @@ -7,10 +7,8 @@ function Set-CIPPSignInState { $APIName = 'Disable User Sign-in', $ExecutingUser ) - 0 - try { - if ($userid -like '*#EXT#*') { $userid = [System.Web.HttpUtility]::UrlEncode($userid) } + try { $body = @{ accountEnabled = [bool]$AccountEnabled } | ConvertTo-Json -Compress -Depth 1 @@ -22,3 +20,4 @@ function Set-CIPPSignInState { return "Could not disable $userid. Error: $($_.Exception.Message)" } } + From e5c613c353099eace4a5bec5294abe2974d4e668 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Mon, 29 Apr 2024 10:39:59 -0400 Subject: [PATCH 08/10] Fix notification casing --- .../CIPP/Settings/Invoke-ExecNotificationConfig.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecNotificationConfig.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecNotificationConfig.ps1 index 24df02441efd..f1f39d9bcc90 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecNotificationConfig.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecNotificationConfig.ps1 @@ -15,7 +15,7 @@ Function Invoke-ExecNotificationConfig { # Write to the Azure Functions log stream. Write-Host 'PowerShell HTTP trigger function processed a request.' $sev = ([pscustomobject]$Request.body.Severity).value -join (',') - $results = try { + $results = try { $Table = Get-CIPPTable -TableName SchedulerConfig $SchedulerConfig = @{ 'tenant' = 'Any' @@ -23,8 +23,8 @@ Function Invoke-ExecNotificationConfig { 'type' = 'CIPPNotifications' 'schedule' = 'Every 15 minutes' 'Severity' = [string]$sev - 'email' = "$($Request.Body.Email)" - 'webhook' = "$($Request.Body.Webhook)" + 'email' = "$($Request.Body.email)" + 'webhook' = "$($Request.Body.webhook)" 'onePerTenant' = [boolean]$Request.Body.onePerTenant 'sendtoIntegration' = [boolean]$Request.Body.sendtoIntegration 'includeTenantId' = [boolean]$Request.Body.includeTenantId @@ -32,7 +32,7 @@ Function Invoke-ExecNotificationConfig { 'RowKey' = 'CippNotifications' } foreach ($logvalue in [pscustomobject]$Request.body.logsToInclude) { - $SchedulerConfig[([pscustomobject]$logvalue.value)] = $true + $SchedulerConfig[([pscustomobject]$logvalue.value)] = $true } Add-CIPPAzDataTableEntity @Table -Entity $SchedulerConfig -Force | Out-Null From 89a8a945518db53a11ef775c3bdf3297893f7c34 Mon Sep 17 00:00:00 2001 From: Esco Date: Thu, 25 Apr 2024 13:48:02 +0200 Subject: [PATCH 09/10] Added Places/Rooms --- .../Entrypoints/Invoke-ListRoomLists.ps1 | 41 +++++++++++++++++++ .../Public/Entrypoints/Invoke-ListRooms.ps1 | 41 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Modules/CIPPCore/Public/Entrypoints/Invoke-ListRoomLists.ps1 create mode 100644 Modules/CIPPCore/Public/Entrypoints/Invoke-ListRooms.ps1 diff --git a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListRoomLists.ps1 b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListRoomLists.ps1 new file mode 100644 index 000000000000..74148522dec5 --- /dev/null +++ b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListRoomLists.ps1 @@ -0,0 +1,41 @@ +using namespace System.Net + +Function Invoke-ListRoomLists { + <# + .FUNCTIONALITY + Entrypoint + #> + [CmdletBinding()] + param($Request, $TriggerMetadata) + + $APIName = $TriggerMetadata.FunctionName + Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' + + + # Write to the Azure Functions log stream. + Write-Host 'PowerShell HTTP trigger function processed a request.' + + # Interact with query parameters or the body of the request. + $TenantFilter = $Request.Query.TenantFilter + + try { + $params = @{ + uri = 'https://graph.microsoft.com/beta/places/microsoft.graph.roomlist' + tenantid = $TenantFilter + AsApp = $true + } + $GraphRequest = New-GraphGetRequest @params + + $StatusCode = [HttpStatusCode]::OK + } catch { + $ErrorMessage = Get-NormalizedError -Message $_.Exception.Message + $StatusCode = [HttpStatusCode]::Forbidden + $GraphRequest = $ErrorMessage + } + # Associate values to output bindings by calling 'Push-OutputBinding'. + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ + StatusCode = $StatusCode + Body = @($GraphRequest | Sort-Object displayName) + }) + +} diff --git a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListRooms.ps1 b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListRooms.ps1 new file mode 100644 index 000000000000..4e2f57124129 --- /dev/null +++ b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListRooms.ps1 @@ -0,0 +1,41 @@ +using namespace System.Net + +Function Invoke-ListRooms { + <# + .FUNCTIONALITY + Entrypoint + #> + [CmdletBinding()] + param($Request, $TriggerMetadata) + + $APIName = $TriggerMetadata.FunctionName + Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' + + + # Write to the Azure Functions log stream. + Write-Host 'PowerShell HTTP trigger function processed a request.' + + # Interact with query parameters or the body of the request. + $TenantFilter = $Request.Query.TenantFilter + + try { + $params = @{ + uri = 'https://graph.microsoft.com/beta/places/microsoft.graph.room' + tenantid = $TenantFilter + AsApp = $true + } + $GraphRequest = New-GraphGetRequest @params + + $StatusCode = [HttpStatusCode]::OK + } catch { + $ErrorMessage = Get-NormalizedError -Message $_.Exception.Message + $StatusCode = [HttpStatusCode]::Forbidden + $GraphRequest = $ErrorMessage + } + # Associate values to output bindings by calling 'Push-OutputBinding'. + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ + StatusCode = $StatusCode + Body = @($GraphRequest | Sort-Object displayName) + }) + +} From 45e68a86d141d861f5e3caa194cb4652fb066e1b Mon Sep 17 00:00:00 2001 From: John Duprey Date: Mon, 29 Apr 2024 11:02:59 -0400 Subject: [PATCH 10/10] up version --- version_latest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version_latest.txt b/version_latest.txt index 566ac6388b64..d6a86bf436c0 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -5.6.1 \ No newline at end of file +5.6.2