Skip to content

Commit 8365037

Browse files
authored
Merge pull request #567 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 0e775da + bc3c5d6 commit 8365037

File tree

9 files changed

+226
-45
lines changed

9 files changed

+226
-45
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function Push-ExecScheduledCommand {
77
$item = $Item | ConvertTo-Json -Depth 100 | ConvertFrom-Json
88
Write-Information "We are going to be running a scheduled task: $($Item.TaskInfo | ConvertTo-Json -Depth 10)"
99

10+
$script:ScheduledTaskId = $Item.TaskInfo.RowKey
11+
1012
$Table = Get-CippTable -tablename 'ScheduledTasks'
1113
$task = $Item.TaskInfo
1214
$commandParameters = $Item.Parameters | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashtable
@@ -21,10 +23,12 @@ function Push-ExecScheduledCommand {
2123
$CurrentTask = Get-AzDataTableEntity @Table -Filter "PartitionKey eq '$($task.PartitionKey)' and RowKey eq '$($task.RowKey)'"
2224
if (!$CurrentTask) {
2325
Write-Information "The task $($task.Name) for tenant $($task.Tenant) does not exist in the ScheduledTasks table. Exiting."
26+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
2427
return
2528
}
2629
if ($CurrentTask.TaskState -eq 'Completed') {
2730
Write-Information "The task $($task.Name) for tenant $($task.Tenant) is already completed. Skipping execution."
31+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
2832
return
2933
}
3034

@@ -69,6 +73,7 @@ function Push-ExecScheduledCommand {
6973
TaskState = 'Planned'
7074
ScheduledTime = [string]$nextRunUnixTime
7175
}
76+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
7277
return
7378
}
7479
}
@@ -94,6 +99,7 @@ function Push-ExecScheduledCommand {
9499
}
95100

96101
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $Tenant -tenantid $TenantInfo.customerId -message "Failed to execute task $($task.Name): The command $($Item.Command) does not exist." -sev Error
102+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
97103
return
98104
}
99105

@@ -330,4 +336,5 @@ function Push-ExecScheduledCommand {
330336
if ($TaskType -ne 'Alert') {
331337
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $Tenant -tenantid $TenantInfo.customerId -message "Successfully executed task: $($task.Name)" -sev Info
332338
}
339+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
333340
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Standards/Push-CIPPStandard.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ function Push-CIPPStandard {
5656
Write-Warning "Error running standard $($Standard) for tenant $($Tenant) - $($_.Exception.Message)"
5757
Write-Information $_.InvocationInfo.PositionMessage
5858
throw $_.Exception.Message
59+
} finally {
60+
Remove-Variable -Name StandardInfo -Scope Script -ErrorAction SilentlyContinue
5961
}
6062
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ExecCopyForSent.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-ExecCopyForSent {
1+
function Invoke-ExecCopyForSent {
22
<#
33
.FUNCTIONALITY
44
Entrypoint
@@ -13,13 +13,21 @@ Function Invoke-ExecCopyForSent {
1313

1414

1515
# Interact with query parameters or the body of the request.
16-
$TenantFilter = $Request.Query.TenantFilter ?? $Request.Body.TenantFilter
16+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
1717
$UserID = $Request.Query.ID ?? $Request.Body.ID
18-
$MessageCopyForSentAsEnabled = $Request.Query.MessageCopyForSentAsEnabled ?? $Request.Body.MessageCopyForSentAsEnabled
19-
$MessageCopyForSentAsEnabled = [System.Convert]::ToBoolean($MessageCopyForSentAsEnabled)
18+
$MessageCopyState = $Request.Query.messageCopyState ?? $Request.Body.messageCopyState
19+
$MessageCopyState = [System.Convert]::ToBoolean($MessageCopyState)
2020

21-
Try {
22-
$Result = Set-CIPPMessageCopy -userid $UserID -tenantFilter $TenantFilter -APIName $APIName -Headers $Headers -MessageCopyForSentAsEnabled $MessageCopyForSentAsEnabled
21+
try {
22+
$params = @{
23+
UserId = $UserID
24+
TenantFilter = $TenantFilter
25+
APIName = $APIName
26+
Headers = $Headers
27+
MessageCopyForSentAsEnabled = $MessageCopyState
28+
MessageCopyForSendOnBehalfEnabled = $MessageCopyState
29+
}
30+
$Result = Set-CIPPMessageCopy @params
2331
$StatusCode = [HttpStatusCode]::OK
2432
} catch {
2533
$Result = "$($_.Exception.Message)"

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Transport/Invoke-AddEditTransportRule.ps1

Lines changed: 179 additions & 27 deletions
Large diffs are not rendered by default.

Modules/CIPPCore/Public/Entrypoints/Invoke-ListLogs.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function Invoke-ListLogs {
8686
$TenantFilter = $Request.Query.Tenant
8787
$ApiFilter = $Request.Query.API
8888
$StandardFilter = $Request.Query.StandardTemplateId
89+
$ScheduledTaskFilter = $Request.Query.ScheduledTaskId
8990

9091
$StartDate = $Request.Query.StartDate ?? $Request.Query.DateFilter
9192
$EndDate = $Request.Query.EndDate ?? $Request.Query.DateFilter
@@ -115,9 +116,10 @@ function Invoke-ListLogs {
115116
$Rows = Get-AzDataTableEntity @Table -Filter $Filter | Where-Object {
116117
$_.Severity -in $LogLevel -and
117118
$_.Username -like $username -and
118-
($TenantFilter -eq $null -or $TenantFilter -eq 'AllTenants' -or $_.Tenant -like "*$TenantFilter*" -or $_.TenantID -eq $TenantFilter) -and
119-
($ApiFilter -eq $null -or $_.API -match "$ApiFilter") -and
120-
($StandardFilter -eq $null -or $_.StandardTemplateId -eq $StandardFilter)
119+
([string]::IsNullOrEmpty($TenantFilter) -or $TenantFilter -eq 'AllTenants' -or $_.Tenant -like "*$TenantFilter*" -or $_.TenantID -eq $TenantFilter) -and
120+
([string]::IsNullOrEmpty($ApiFilter) -or $_.API -match "$ApiFilter") -and
121+
([string]::IsNullOrEmpty($StandardFilter) -or $_.StandardTemplateId -eq $StandardFilter) -and
122+
([string]::IsNullOrEmpty($ScheduledTaskFilter) -or $_.ScheduledTaskId -eq $ScheduledTaskFilter)
121123
}
122124

123125
if ($AllowedTenants -notcontains 'AllTenants') {
@@ -126,7 +128,7 @@ function Invoke-ListLogs {
126128

127129
foreach ($Row in $Rows) {
128130
if ($AllowedTenants -contains 'AllTenants' -or ($AllowedTenants -notcontains 'AllTenants' -and ($TenantList.defaultDomainName -contains $Row.Tenant -or $Row.Tenant -eq 'CIPP' -or $TenantList.customerId -contains $Row.TenantId)) ) {
129-
if ($Row.StandardTemplateId) {
131+
if ($StandardTaskFilter -and $Row.StandardTemplateId) {
130132
$Standard = ($Templates | Where-Object { $_.RowKey -eq $Row.StandardTemplateId }).JSON | ConvertFrom-Json
131133

132134
$StandardInfo = @{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ function Write-LogMessage {
7676
$TableRow.ConditionalAccessTemplateId = [string]$script:StandardInfo.ConditionalAccessTemplateId
7777
}
7878
}
79+
if ($script:ScheduledTaskId) {
80+
$TableRow.ScheduledTaskId = [string]$script:ScheduledTaskId
81+
}
7982

8083
$Table.Entity = $TableRow
8184
Add-CIPPAzDataTableEntity @Table | Out-Null

Modules/CIPPCore/Public/Set-CIPPMessageCopy.ps1

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
function Set-CIPPMessageCopy {
22
[CmdletBinding()]
33
param (
4-
$userid,
4+
$UserId,
55
[bool]$MessageCopyForSentAsEnabled,
6+
[bool]$MessageCopyForSendOnBehalfEnabled,
67
$TenantFilter,
7-
$APIName = 'Manage OneDrive Access',
8+
$APIName = 'Set message copy for sent',
89
$Headers
910
)
10-
Try {
11-
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-Mailbox' -cmdParams @{Identity = $userid; MessageCopyForSentAsEnabled = $MessageCopyForSentAsEnabled }
12-
$Result = "Successfully set MessageCopyForSentAsEnabled as $MessageCopyForSentAsEnabled on $($userid)."
11+
try {
12+
$cmdParams = @{
13+
Identity = $UserId
14+
MessageCopyForSentAsEnabled = $MessageCopyForSentAsEnabled
15+
MessageCopyForSendOnBehalfEnabled = $MessageCopyForSendOnBehalfEnabled
16+
17+
}
18+
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-Mailbox' -cmdParams $cmdParams
19+
$Result = "Successfully set message copy for 'Send as' as $MessageCopyForSentAsEnabled and 'Sent on behalf' as $MessageCopyForSendOnBehalfEnabled on $($UserId)."
1320
Write-LogMessage -headers $Headers -API $APIName -tenant $($TenantFilter) -message $Result -Sev 'Info'
1421
return $Result
1522
} catch {
1623
$ErrorMessage = Get-CippException -Exception $_
17-
$Result = "Failed to set MessageCopyForSentAsEnabled to $MessageCopyForSentAsEnabled - $($ErrorMessage.NormalizedError)"
24+
$Result = "Failed to set message copy for 'Send as' as $MessageCopyForSentAsEnabled and 'Sent on behalf' as $MessageCopyForSendOnBehalfEnabled - $($ErrorMessage.NormalizedError)"
1825
Write-LogMessage -headers $Headers -API $APIName -tenant $($TenantFilter) -message $Result -Sev 'Error' -LogData $ErrorMessage
1926
throw $Result
2027
}

host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"distributedTracingEnabled": false,
1717
"version": "None"
1818
},
19-
"defaultVersion": "8.7.0",
19+
"defaultVersion": "8.7.1",
2020
"versionMatchStrategy": "Strict",
2121
"versionFailureStrategy": "Fail"
2222
}

version_latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.7.0
1+
8.7.1

0 commit comments

Comments
 (0)