Skip to content

Commit bd64968

Browse files
authored
Merge pull request #93 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 30e74bb + fbcd3c3 commit bd64968

File tree

6 files changed

+98
-36
lines changed

6 files changed

+98
-36
lines changed

Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function Add-CIPPScheduledTask {
2323
$Parameters = [System.Collections.Hashtable]@{}
2424
foreach ($Key in $task.Parameters.PSObject.Properties.Name) {
2525
$Param = $task.Parameters.$Key
26+
27+
if ($null -eq $Param -or $Param -eq '' -or ($Param | Measure-Object).Count -eq 0) {
28+
continue
29+
}
2630
if ($Param -is [System.Collections.IDictionary] -or $Param.Key) {
2731
$ht = @{}
2832
foreach ($p in $Param.GetEnumerator()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function Push-ExecScheduledCommand {
4040
Write-Host "Failed to remove parameters: $($_.Exception.Message)"
4141
}
4242

43-
$tenant = $Item.Parameters.TenantFilter
43+
$tenant = $Item.Parameters.TenantFilter ?? $Item.Tenant
4444
Write-Host "Started Task: $($Item.Command) for tenant: $tenant"
4545
try {
4646

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/GDAP/Invoke-ExecGDAPInvite.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ Function Invoke-ExecGDAPInvite {
8282
} catch {
8383
$Message = 'Error creating GDAP relationship, failed at step: ' + $Step
8484
Write-Host "GDAP ERROR: $($_.InvocationInfo.PositionMessage)"
85-
Write-LogMessage -headers $Request.Headers -API $APINAME -tenant $env:TenantID -message "$($Message): $($_.Exception.Message)" -Sev 'Error' -LogData (Get-CippException -Exception $_)
85+
86+
if ($Step -eq 'Creating GDAP relationship' -and $_.Exception.Message -match 'The user (principal) does not have the required permissions to perform the specified action on the resource.') {
87+
$Message = 'Error creating GDAP relationship, ensure that all users have MFA enabled and enforced without exception. Please see the Microsoft Partner Security Requirements documentation for more information. https://learn.microsoft.com/en-us/partner-center/security/partner-security-requirements'
88+
} else {
89+
$Message = "$($Message): $($_.Exception.Message)"
90+
}
91+
92+
Write-LogMessage -headers $Request.Headers -API $APINAME -tenant $env:TenantID -message $Message -Sev 'Error' -LogData (Get-CippException -Exception $_)
8693
}
8794

8895
$body = @{

Modules/CIPPCore/Public/Invoke-CIPPStandardsRun.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function Invoke-CIPPStandardsRun {
3434
runManually = $runManually
3535
}
3636
}
37+
SkipLog = $true
3738
}
3839
if ($TemplateID) {
3940
$InputObject.QueueFunction.StandardParams['TemplateId'] = $TemplateID
Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
function Invoke-CippGraphWebhookRenewal {
2-
$RenewalDate = (Get-Date).AddDays(1).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
2+
$RenewalDate = (Get-Date).AddDays(1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ')
33
$body = @{
4-
"expirationDateTime" = "$RenewalDate"
4+
'expirationDateTime' = "$RenewalDate"
55
} | ConvertTo-Json
66

7-
87
$WebhookTable = Get-CIPPTable -TableName webhookTable
9-
$WebhookData = Get-AzDataTableEntity @WebhookTable | Where-Object { $null -ne $_.SubscriptionID -and $_.SubscriptionID -ne '' -and ((Get-Date($_.Expiration)) -le ((Get-Date).AddHours(2))) }
8+
try {
9+
$WebhookData = Get-AzDataTableEntity @WebhookTable | Where-Object { $null -ne $_.SubscriptionID -and $_.SubscriptionID -ne '' -and ((Get-Date($_.Expiration)) -le ((Get-Date).AddHours(2))) }
10+
} catch {
11+
$WebhookData = @()
12+
}
1013

11-
foreach ($UpdateSub in $WebhookData) {
12-
try {
13-
$TenantFilter = $UpdateSub.PartitionKey
14+
if (($WebhookData | Measure-Object).Count -gt 0) {
15+
foreach ($UpdateSub in $WebhookData) {
1416
try {
15-
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/subscriptions/$($UpdateSub.SubscriptionID)" -tenantid $TenantFilter -type PATCH -body $body -Verbose
16-
$UpdateSub.Expiration = $RenewalDate
17-
$null = Add-AzDataTableEntity @WebhookTable -Entity $UpdateSub -Force
18-
Write-LogMessage -Headers'CIPP' -API 'Renew_Graph_Subscriptions' -message "Renewed Subscription:$($UpdateSub.SubscriptionID)" -Sev "Info" -tenant $TenantFilter
19-
20-
} catch {
21-
# Rebuild creation parameters
22-
$BaseURL = "$(([uri]($UpdateSub.WebhookNotificationUrl)).Host)"
23-
if ($UpdateSub.TypeofSubscription) {
24-
$TypeofSubscription = "$($UpdateSub.TypeofSubscription)"
25-
} else {
26-
$TypeofSubscription = 'updated'
17+
$TenantFilter = $UpdateSub.PartitionKey
18+
try {
19+
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/subscriptions/$($UpdateSub.SubscriptionID)" -tenantid $TenantFilter -type PATCH -body $body -Verbose
20+
$UpdateSub.Expiration = $RenewalDate
21+
$null = Add-AzDataTableEntity @WebhookTable -Entity $UpdateSub -Force
22+
Write-LogMessage -API 'Renew_Graph_Subscriptions' -message "Renewed Subscription:$($UpdateSub.SubscriptionID)" -Sev 'Info' -tenant $TenantFilter
23+
24+
} catch {
25+
# Rebuild creation parameters
26+
$BaseURL = "$(([uri]($UpdateSub.WebhookNotificationUrl)).Host)"
27+
if ($UpdateSub.TypeofSubscription) {
28+
$TypeofSubscription = "$($UpdateSub.TypeofSubscription)"
29+
} else {
30+
$TypeofSubscription = 'updated'
31+
}
32+
$Resource = "$($UpdateSub.Resource)"
33+
$EventType = "$($UpdateSub.EventType)"
34+
35+
Write-LogMessage -API 'Renew_Graph_Subscriptions' -message "Recreating: $($UpdateSub.SubscriptionID) as renewal failed." -Sev 'Info' -tenant $TenantFilter
36+
$CreateResult = New-CIPPGraphSubscription -TenantFilter $TenantFilter -TypeofSubscription $TypeofSubscription -BaseURL $BaseURL -Resource $Resource -EventType $EventType -Headers 'GraphSubscriptionRenewal' -Recreate
37+
38+
if ($CreateResult -match 'Created Webhook subscription for') {
39+
Remove-AzDataTableEntity -Force @WebhookTable -Entity $UpdateSub
40+
}
2741
}
28-
$Resource = "$($UpdateSub.Resource)"
29-
$EventType = "$($UpdateSub.EventType)"
30-
31-
Write-LogMessage -Headers'CIPP' -API 'Renew_Graph_Subscriptions' -message "Recreating: $($UpdateSub.SubscriptionID) as renewal failed." -Sev "Info" -tenant $TenantFilter
32-
$CreateResult = New-CIPPGraphSubscription -TenantFilter $TenantFilter -TypeofSubscription $TypeofSubscription -BaseURL $BaseURL -Resource $Resource -EventType $EventType -Headers 'GraphSubscriptionRenewal' -Recreate
33-
34-
if ($CreateResult -match 'Created Webhook subscription for') {
35-
Remove-AzDataTableEntity -Force @WebhookTable -Entity $UpdateSub
36-
}
37-
42+
} catch {
43+
Write-LogMessage -API 'Renew_Graph_Subscriptions' -message "Failed to renew Webhook Subscription: $($UpdateSub.SubscriptionID). Linenumber: $($_.InvocationInfo.ScriptLineNumber) Error: $($_.Exception.message)" -Sev 'Error' -tenant $TenantFilter
3844
}
39-
40-
41-
} catch {
42-
Write-LogMessage -Headers'CIPP' -API 'Renew_Graph_Subscriptions' -message "Failed to renew Webhook Subscription: $($UpdateSub.SubscriptionID). Linenumber: $($_.InvocationInfo.ScriptLineNumber) Error: $($_.Exception.message)" -Sev "Error" -tenant $TenantFilter
4345
}
4446
}
4547
}

Modules/CippExtensions/Public/Halo/New-HaloPSATicket.ps1

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,46 @@ function New-HaloPSATicket {
88
#Get Halo PSA Token based on the config we have.
99
$Table = Get-CIPPTable -TableName Extensionsconfig
1010
$Configuration = ((Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json).HaloPSA
11-
11+
$TicketTable = Get-CIPPTable -TableName 'PSATickets'
1212
$token = Get-HaloToken -configuration $Configuration
13+
14+
if ($Configuration.ConsolidateTickets) {
15+
$ExistingTicket = Get-CIPPAzDataTableEntity @TicketTable -Filter "PartitionKey eq 'HaloPSA' and RowKey eq '$($client)-$($title)'"
16+
if ($ExistingTicket) {
17+
Write-Information "Ticket already exists in HaloPSA: $($ExistingTicket.TicketID)"
18+
19+
$Ticket = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Tickets/$($ExistingTicket.TicketID)?includedetails=true&includelastaction=false&nocache=undefined&includeusersassets=false&isdetailscreen=true" -ContentType 'application/json; charset=utf-8' -Method Get -Headers @{Authorization = "Bearer $($token.access_token)" }
20+
if (!$Ticket.hasbeenclosed) {
21+
Write-Information 'Ticket is still open, adding new note'
22+
$Object = [PSCustomObject]@{
23+
ticket_id = $ExistingTicket.TicketID
24+
outcome = 'Private Note'
25+
outcome_id = 7
26+
hiddenfromuser = $true
27+
note_html = $description
28+
}
29+
$body = ConvertTo-Json -Compress -Depth 10 -InputObject @($Object)
30+
try {
31+
if ($PSCmdlet.ShouldProcess('Add note to HaloPSA ticket', 'Add note')) {
32+
$Action = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/actions" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
33+
Write-Information "Note added to ticket in HaloPSA: $($Action.id)"
34+
}
35+
return
36+
} catch {
37+
$Message = if ($_.ErrorDetails.Message) {
38+
Get-NormalizedError -Message $_.ErrorDetails.Message
39+
} else {
40+
$_.Exception.message
41+
}
42+
Write-LogMessage -message "Failed to add note to HaloPSA ticket: $Message" -API 'HaloPSATicket' -sev Error -LogData (Get-CippException -Exception $_)
43+
Write-Information "Failed to add note to HaloPSA ticket: $Message"
44+
Write-Information "Body we tried to ship: $body"
45+
return
46+
}
47+
}
48+
}
49+
}
50+
1351
$Object = [PSCustomObject]@{
1452
files = $null
1553
usertype = 1
@@ -41,6 +79,16 @@ function New-HaloPSATicket {
4179
if ($PSCmdlet.ShouldProcess('Send ticket to HaloPSA', 'Create ticket')) {
4280
$Ticket = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/Tickets" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
4381
Write-Information "Ticket created in HaloPSA: $($Ticket.id)"
82+
83+
if ($Configuration.ConsolidateTickets) {
84+
$TicketObject = [PSCustomObject]@{
85+
PartitionKey = 'HaloPSA'
86+
RowKey = "$($client)-$($title)"
87+
TicketID = $Ticket.id
88+
}
89+
Add-CIPPAzDataTableEntity @TicketTable -Entity $TicketObject -Force
90+
Write-Information 'Ticket added to consolidation table'
91+
}
4492
}
4593
} catch {
4694
$Message = if ($_.ErrorDetails.Message) {

0 commit comments

Comments
 (0)