From 20c44ff9c841ca7d044bb1e58c7c13e49c8f29fc Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Fri, 13 Oct 2023 23:27:43 +0200 Subject: [PATCH 1/7] removed delete, cleaned up error. --- Modules/CIPPCore/Public/Set-CIPPCPVConsent.ps1 | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Modules/CIPPCore/Public/Set-CIPPCPVConsent.ps1 b/Modules/CIPPCore/Public/Set-CIPPCPVConsent.ps1 index 4a44db86a958..34db91662aa0 100644 --- a/Modules/CIPPCore/Public/Set-CIPPCPVConsent.ps1 +++ b/Modules/CIPPCore/Public/Set-CIPPCPVConsent.ps1 @@ -10,14 +10,6 @@ function Set-CIPPCPVConsent { $TenantName = $Tenant.defaultDomainName $TenantFilter = $Tenant.customerId - try { - $DeleteOldPermissions = New-GraphpostRequest -Type DELETE -noauthcheck $true -uri "https://api.partnercenter.microsoft.com/v1/customers/$($TenantFilter)/applicationconsents/$($env:ApplicationID)" -scope "https://api.partnercenter.microsoft.com/.default" -tenantid $env:TenantID - - } - catch { - "There is no existing CPV Application Consent for $($TenantName). Adding a new application." - } - try { $AppBody = @" { @@ -41,6 +33,9 @@ function Set-CIPPCPVConsent { } catch { + $ErrorMessage = $_.Exception.Message + if ($ErrorMessage -like '*409 (Conflict)*') { return @("We've already added our Service Principal to $($TenantName)") } + Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Could not add our Service Principal to the client tenant $($TenantName): $($_.Exception.message)" -Sev "Error" -tenant $($Tenantfilter) return @("Could not add our Service Principal to the client tenant $($TenantName): $($_.Exception.message)") } From fad01ae8c071fd08db88d59060294f40ff4f907d Mon Sep 17 00:00:00 2001 From: BNWEIN Date: Sat, 14 Oct 2023 08:22:29 +0100 Subject: [PATCH 2/7] Fixed Alert Error Fixed double -tenant line 124 --- Scheduler_CIPPNotifications/run.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scheduler_CIPPNotifications/run.ps1 b/Scheduler_CIPPNotifications/run.ps1 index 59d8066f67e1..e2daabff52c0 100644 --- a/Scheduler_CIPPNotifications/run.ps1 +++ b/Scheduler_CIPPNotifications/run.ps1 @@ -121,7 +121,7 @@ try { Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody } } - Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Sent Webhook to $($config.webhook) " -tenant $Tenant -sev info + Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Sent Webhook to $($config.webhook) " -sev info } $UpdateLogs = $CurrentLog | ForEach-Object { From 1eb86a9a6500e3209baccdb787756cfe072385c7 Mon Sep 17 00:00:00 2001 From: BNWEIN Date: Sat, 14 Oct 2023 14:27:22 +0100 Subject: [PATCH 3/7] Update run.ps1 Changed to write-log to $JSONRecipients --- Scheduler_CIPPNotifications/run.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scheduler_CIPPNotifications/run.ps1 b/Scheduler_CIPPNotifications/run.ps1 index e2daabff52c0..d8826cfa21d5 100644 --- a/Scheduler_CIPPNotifications/run.ps1 +++ b/Scheduler_CIPPNotifications/run.ps1 @@ -49,7 +49,7 @@ try { } "@ New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/me/sendMail' -tenantid $env:TenantID -type POST -body ($JSONBody) - Write-LogMessage -API 'Alerts' -message "Sent alerts to: $($Config.email)" -tenant $Tenant -sev info + Write-LogMessage -API 'Alerts' -message "Sent alerts to: $($JSONRecipients)" -tenant $Tenant -sev info } } } From dc4fa1ba3d7c5ce78cd4557ac09079358dc61e7f Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Sat, 14 Oct 2023 16:12:07 +0200 Subject: [PATCH 4/7] None as tenant for halo --- Modules/CippExtensions/Private/Get-HaloToken.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CippExtensions/Private/Get-HaloToken.ps1 b/Modules/CippExtensions/Private/Get-HaloToken.ps1 index 2e0ed6e8c30b..bc75822a9875 100644 --- a/Modules/CippExtensions/Private/Get-HaloToken.ps1 +++ b/Modules/CippExtensions/Private/Get-HaloToken.ps1 @@ -11,7 +11,7 @@ function Get-HaloToken { client_secret = (Get-AzKeyVaultSecret -VaultName $ENV:WEBSITE_DEPLOYMENT_ID -Name 'HaloPSA' -AsPlainText) scope = 'all' } - if (!([string]::IsNullOrEmpty($Configuration.Tenant))) { $Tenant = "?tenant=$($Configuration.tenant)" } + if ($Configuration.Tenant -ne "None") { $Tenant = "?tenant=$($Configuration.tenant)" } $token = Invoke-RestMethod -Uri "$($Configuration.AuthURL)/token$Tenant" -Method Post -Body $body -ContentType 'application/x-www-form-urlencoded' return $token } From c9b5b30f7ff5c6c874dd33300022b93d41207148 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Sat, 14 Oct 2023 16:12:35 +0200 Subject: [PATCH 5/7] upped version --- version_latest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version_latest.txt b/version_latest.txt index f93922292263..f0f76fb69328 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -4.4.2 \ No newline at end of file +4.4.3 \ No newline at end of file From 0f625b8093373268e90abbe9478daea51179a833 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Sat, 14 Oct 2023 18:40:28 +0200 Subject: [PATCH 6/7] added listlogs to debug. --- ListLogs/run.ps1 | 2 +- Scheduler_CIPPNotifications/run.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ListLogs/run.ps1 b/ListLogs/run.ps1 index d95f392f5a90..3f4d59a2477c 100644 --- a/ListLogs/run.ps1 +++ b/ListLogs/run.ps1 @@ -4,7 +4,7 @@ using namespace System.Net param($Request, $TriggerMetadata) $APIName = $TriggerMetadata.FunctionName -Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Info' +Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' if ($request.Query.Filter -eq 'True') { $LogLevel = if ($Request.query.Severity) { ($Request.query.Severity).split(',') } else { 'Info', 'Warn', 'Error', 'Critical', 'Alert' } diff --git a/Scheduler_CIPPNotifications/run.ps1 b/Scheduler_CIPPNotifications/run.ps1 index d8826cfa21d5..86dea5a7b615 100644 --- a/Scheduler_CIPPNotifications/run.ps1 +++ b/Scheduler_CIPPNotifications/run.ps1 @@ -121,7 +121,7 @@ try { Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody } } - Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Sent Webhook to $($config.webhook) " -sev info + Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Sent Webhook to $($config.webhook)" -sev Debug } $UpdateLogs = $CurrentLog | ForEach-Object { From 8aa92cb1209d385cebe4a6b20d8c218a2ea32d2c Mon Sep 17 00:00:00 2001 From: KelvinTegelaar Date: Sat, 14 Oct 2023 18:43:15 +0200 Subject: [PATCH 7/7] 4.4.4 looks nicer. --- version_latest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version_latest.txt b/version_latest.txt index f0f76fb69328..f15ec04e09e0 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -4.4.3 \ No newline at end of file +4.4.4 \ No newline at end of file