Skip to content

Commit bf4b65c

Browse files
measure changes
1 parent 331a0c7 commit bf4b65c

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

Modules/CIPPCore/Public/New-CIPPBackupTask.ps1

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ function New-CIPPBackupTask {
2727
}
2828
'users' {
2929
Measure-CippTask -TaskName 'Users' -EventName 'CIPP.BackupCompleted' -Script {
30-
$Users = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/users?$top=999' -tenantid $TenantFilter | Select-Object * -ExcludeProperty mail, provisionedPlans, onPrem*, *passwordProfile*, *serviceProvisioningErrors*, isLicenseReconciliationNeeded, isManagementRestricted, isResourceAccount, *date*, *external*, identities, deletedDateTime, isSipEnabled, assignedPlans, cloudRealtimeCommunicationInfo, deviceKeys, provisionedPlan, securityIdentifier
31-
#remove the property if the value is $null
32-
$users = $Users | ForEach-Object {
30+
New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/users?$top=999' -tenantid $TenantFilter | Select-Object * -ExcludeProperty mail, provisionedPlans, onPrem*, *passwordProfile*, *serviceProvisioningErrors*, isLicenseReconciliationNeeded, isManagementRestricted, isResourceAccount, *date*, *external*, identities, deletedDateTime, isSipEnabled, assignedPlans, cloudRealtimeCommunicationInfo, deviceKeys, provisionedPlan, securityIdentifier | ForEach-Object {
31+
#remove the property if the value is $null
3332
$_.psobject.properties | Where-Object { $null -eq $_.Value } | ForEach-Object {
3433
$_.psobject.properties.Remove($_.Name)
3534
}
35+
$_
3636
}
37-
$Users
3837
}
3938
}
4039
'groups' {
@@ -102,19 +101,18 @@ function New-CIPPBackupTask {
102101

103102
'antispam' {
104103
Measure-CippTask -TaskName 'AntiSpam' -EventName 'CIPP.BackupCompleted' -Script {
105-
$Policies = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-HostedContentFilterPolicy' | Select-Object * -ExcludeProperty *odata*, *data.type*
106-
$Rules = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-HostedContentFilterRule' | Select-Object * -ExcludeProperty *odata*, *data.type*
107-
108-
$Policies | ForEach-Object {
104+
$Policies = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-HostedContentFilterPolicy' | Select-Object * -ExcludeProperty *odata*, *data.type* | ForEach-Object {
109105
$_.psobject.properties | Where-Object { $null -eq $_.Value } | ForEach-Object {
110106
$_.psobject.properties.Remove($_.Name)
111107
}
108+
$_
112109
}
113110

114-
$Rules | ForEach-Object {
111+
$Rules = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-HostedContentFilterRule' | Select-Object * -ExcludeProperty *odata*, *data.type* | ForEach-Object {
115112
$_.psobject.properties | Where-Object { $null -eq $_.Value } | ForEach-Object {
116113
$_.psobject.properties.Remove($_.Name)
117114
}
115+
$_
118116
}
119117

120118
@{ policies = $Policies; rules = $Rules } | ConvertTo-Json -Depth 10
@@ -123,19 +121,18 @@ function New-CIPPBackupTask {
123121

124122
'antiphishing' {
125123
Measure-CippTask -TaskName 'AntiPhishing' -EventName 'CIPP.BackupCompleted' -Script {
126-
$Policies = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-AntiPhishPolicy' | Select-Object * -ExcludeProperty *odata*, *data.type*
127-
$Rules = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-AntiPhishRule' | Select-Object * -ExcludeProperty *odata*, *data.type*
128-
129-
$Policies | ForEach-Object {
124+
$Policies = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-AntiPhishPolicy' | Select-Object * -ExcludeProperty *odata*, *data.type* | ForEach-Object {
130125
$_.psobject.properties | Where-Object { $null -eq $_.Value } | ForEach-Object {
131126
$_.psobject.properties.Remove($_.Name)
132127
}
128+
$_
133129
}
134130

135-
$Rules | ForEach-Object {
131+
$Rules = New-ExoRequest -tenantid $Tenantfilter -cmdlet 'Get-AntiPhishRule' | Select-Object * -ExcludeProperty *odata*, *data.type* | ForEach-Object {
136132
$_.psobject.properties | Where-Object { $null -eq $_.Value } | ForEach-Object {
137133
$_.psobject.properties.Remove($_.Name)
138134
}
135+
$_
139136
}
140137

141138
@{ policies = $Policies; rules = $Rules } | ConvertTo-Json -Depth 10

Modules/CIPPCore/Public/Tools/Measure-CippTask.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function Measure-CippTask {
5151
$errorMessage = $null
5252

5353
try {
54-
# Execute the actual task
55-
$result = & $Script
54+
# Execute the actual task (use dot-sourcing to preserve parent scope variables)
55+
$result = . $Script
5656
} catch {
5757
$errorOccurred = $true
5858
$errorMessage = $_.Exception.Message

0 commit comments

Comments
 (0)