Skip to content

Commit d782fb4

Browse files
authored
Merge pull request #397 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 6b3f8ad + 4a0f291 commit d782fb4

File tree

118 files changed

+1473
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1473
-241
lines changed

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

Lines changed: 276 additions & 82 deletions
Large diffs are not rendered by default.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ Function Invoke-ExecGDAPRoleTemplate {
2020
if ($Request.Query.TemplateId) {
2121
$Template = $Templates | Where-Object -Property RowKey -EQ $Request.Query.TemplateId
2222
if (!$Template) {
23+
Write-LogMessage -headers $Headers -API $APIName -message "GDAP role template '$($Request.Query.TemplateId)' not found" -Sev 'Warning'
2324
$Body = @{}
2425
} else {
26+
Write-LogMessage -headers $Headers -API $APIName -message "Retrieved GDAP role template '$($Request.Query.TemplateId)'" -Sev 'Info'
2527
$Body = @{
2628
TemplateId = $Template.RowKey
2729
RoleMappings = @($Template.RoleMappings | ConvertFrom-Json)
@@ -38,6 +40,7 @@ Function Invoke-ExecGDAPRoleTemplate {
3840
}
3941
Write-Information ($RoleMappings | ConvertTo-Json)
4042
Add-CIPPGDAPRoleTemplate -TemplateId $RowKey -RoleMappings $RoleMappings
43+
Write-LogMessage -headers $Headers -API $APIName -message "Added role mappings to GDAP template '$RowKey'" -Sev 'Info'
4144
$Body = @{
4245
Results = "Added role mappings to template $RowKey"
4346
}
@@ -48,10 +51,12 @@ Function Invoke-ExecGDAPRoleTemplate {
4851
if ($Template) {
4952
$RoleMappings = $Request.Body.RoleMappings
5053
Add-CIPPGDAPRoleTemplate -TemplateId $RowKey -RoleMappings $RoleMappings -Overwrite
54+
Write-LogMessage -headers $Headers -API $APIName -message "Updated role mappings for GDAP template '$RowKey'" -Sev 'Info'
5155
$Body = @{
5256
Results = "Updated role mappings for template $RowKey"
5357
}
5458
} else {
59+
Write-LogMessage -headers $Headers -API $APIName -message "GDAP role template '$RowKey' not found for editing" -Sev 'Warning'
5560
$Body = @{
5661
Results = "Template $RowKey not found"
5762
}
@@ -62,16 +67,19 @@ Function Invoke-ExecGDAPRoleTemplate {
6267
$Template = $Templates | Where-Object -Property RowKey -EQ $RowKey
6368
if ($Template) {
6469
Remove-AzDataTableEntity -Force @Table -Entity $Template
70+
Write-LogMessage -headers $Headers -API $APIName -message "Deleted GDAP role template '$RowKey'" -Sev 'Info'
6571
$Body = @{
6672
Results = "Deleted template $RowKey"
6773
}
6874
} else {
75+
Write-LogMessage -headers $Headers -API $APIName -message "GDAP role template '$RowKey' not found for deletion" -Sev 'Warning'
6976
$Body = @{
7077
Results = "Template $RowKey not found"
7178
}
7279
}
7380
}
7481
default {
82+
Write-LogMessage -headers $Headers -API $APIName -message "Retrieved $($Templates.Count) GDAP role templates" -Sev 'Info'
7583
$Results = foreach ($Template in $Templates) {
7684
[PSCustomObject]@{
7785
TemplateId = $Template.RowKey

Modules/CIPPCore/Public/Get-CIPPTextReplacement.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function Get-CIPPTextReplacement {
2626
'%temp%',
2727
'%tenantid%',
2828
'%tenantfilter%',
29+
'%initialdomain%',
2930
'%tenantname%',
3031
'%partnertenantid%',
3132
'%samappid%',
@@ -37,7 +38,7 @@ function Get-CIPPTextReplacement {
3738
'%programfiles(x86)%',
3839
'%programdata%'
3940
)
40-
41+
4142
$Tenant = Get-Tenants -TenantFilter $TenantFilter
4243
$CustomerId = $Tenant.customerId
4344

@@ -70,6 +71,7 @@ function Get-CIPPTextReplacement {
7071
#default replacements for all tenants: %tenantid% becomes $tenant.customerId, %tenantfilter% becomes $tenant.defaultDomainName, %tenantname% becomes $tenant.displayName
7172
$Text = $Text -replace '%tenantid%', $Tenant.customerId
7273
$Text = $Text -replace '%tenantfilter%', $Tenant.defaultDomainName
74+
$Text = $Text -replace '%initialdomain%', $Tenant.initialDomainName
7375
$Text = $Text -replace '%tenantname%', $Tenant.displayName
7476

7577
# Partner specific replacements

Modules/CIPPCore/Public/GraphHelper/New-ExoBulkRequest.ps1

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function New-ExoBulkRequest {
4343

4444
# Initialize the ID to Cmdlet Name mapping
4545
$IdToCmdletName = @{}
46+
$IdToOperationGuid = @{} # Track operation GUIDs when provided
4647

4748
# Split the cmdletArray into batches of 10
4849
$batches = [System.Collections.Generic.List[object]]::new()
@@ -69,19 +70,32 @@ function New-ExoBulkRequest {
6970
$Headers['Accept'] = 'application/json; odata.metadata=minimal'
7071
$Headers['Accept-Encoding'] = 'gzip'
7172

72-
# Generate a unique ID for each request
73-
$RequestId = [Guid]::NewGuid().ToString()
73+
# Use provided OperationGuid if available, otherwise generate one
74+
$RequestId = if ($cmd.OperationGuid) {
75+
$cmd.OperationGuid
76+
} else {
77+
[Guid]::NewGuid().ToString()
78+
}
79+
80+
# Create clean cmdlet object for API (without OperationGuid)
81+
$CleanCmd = @{
82+
CmdletInput = $cmd.CmdletInput
83+
}
84+
7485
$BatchRequest = @{
7586
url = $URL
7687
method = 'POST'
77-
body = $cmd
88+
body = $CleanCmd
7889
headers = $Headers.Clone()
7990
id = $RequestId
8091
}
8192
$BatchBodyObj['requests'] = $BatchBodyObj['requests'] + $BatchRequest
8293

83-
# Map the Request ID to the Cmdlet Name
94+
# Map the Request ID to the Cmdlet Name and Operation GUID (if provided)
8495
$IdToCmdletName[$RequestId] = $cmd.CmdletInput.CmdletName
96+
if ($cmd.OperationGuid) {
97+
$IdToOperationGuid[$RequestId] = $cmd.OperationGuid
98+
}
8599
}
86100
$BatchBodyJson = ConvertTo-Json -InputObject $BatchBodyObj -Depth 10
87101
$BatchBodyJson = Get-CIPPTextReplacement -TenantFilter $tenantid -Text $BatchBodyJson
@@ -104,6 +118,7 @@ function New-ExoBulkRequest {
104118
foreach ($item in $ReturnedData) {
105119
$itemId = $item.id
106120
$CmdletName = $IdToCmdletName[$itemId]
121+
$OperationGuid = $IdToOperationGuid[$itemId] # Will be $null if not provided
107122
$body = $item.body.PSObject.Copy()
108123

109124
if ($body.'@adminapi.warnings') {
@@ -115,20 +130,50 @@ function New-ExoBulkRequest {
115130
} else {
116131
$msg = [pscustomobject]@{ error = $body.error.message; target = $body.error.details.target }
117132
}
133+
134+
# Add OperationGuid to error if it was provided
135+
if ($OperationGuid) {
136+
$msg | Add-Member -MemberType NoteProperty -Name 'OperationGuid' -Value $OperationGuid -Force
137+
}
138+
118139
$body | Add-Member -MemberType NoteProperty -Name 'value' -Value $msg -Force
140+
} else {
141+
# Handle successful operations - add OperationGuid if provided
142+
if ($body.value) {
143+
# Add GUID to existing results if provided
144+
if ($OperationGuid) {
145+
if ($body.value -is [array]) {
146+
foreach ($val in $body.value) {
147+
$val | Add-Member -MemberType NoteProperty -Name 'OperationGuid' -Value $OperationGuid -Force
148+
}
149+
} else {
150+
$body.value | Add-Member -MemberType NoteProperty -Name 'OperationGuid' -Value $OperationGuid -Force
151+
}
152+
}
153+
} else {
154+
# Create success indicators when GUID was provided (caller wants tracking)
155+
if ($OperationGuid) {
156+
$body | Add-Member -MemberType NoteProperty -Name 'value' -Value ([pscustomobject]@{
157+
Success = $true
158+
OperationGuid = $OperationGuid
159+
}) -Force
160+
}
161+
}
119162
}
163+
120164
$resultValues = $body.value
121165
foreach ($resultValue in $resultValues) {
122166
if (-not $FinalData.ContainsKey($CmdletName)) {
123167
$FinalData[$CmdletName] = [System.Collections.Generic.List[object]]::new()
124-
$FinalData.$CmdletName.Add($resultValue)
168+
$FinalData[$CmdletName].Add($resultValue)
125169
} else {
126-
$FinalData.$CmdletName.Add($resultValue)
170+
$FinalData[$CmdletName].Add($resultValue)
127171
}
128172
}
129173
}
130174
} else {
131175
$FinalData = foreach ($item in $ReturnedData) {
176+
$OperationGuid = $IdToOperationGuid[$item.id] # Will be $null if not provided
132177
$body = $item.body.PSObject.Copy()
133178

134179
if ($body.'@adminapi.warnings') {
@@ -140,7 +185,35 @@ function New-ExoBulkRequest {
140185
} else {
141186
$msg = [pscustomobject]@{ error = $body.error.message; target = $body.error.details.target }
142187
}
188+
189+
# Add OperationGuid to error if it was provided
190+
if ($OperationGuid) {
191+
$msg | Add-Member -MemberType NoteProperty -Name 'OperationGuid' -Value $OperationGuid -Force
192+
}
193+
143194
$body | Add-Member -MemberType NoteProperty -Name 'value' -Value $msg -Force
195+
} else {
196+
# Handle successful operations
197+
if ($body.value) {
198+
# Add GUID to existing results if provided
199+
if ($OperationGuid) {
200+
if ($body.value -is [array]) {
201+
foreach ($val in $body.value) {
202+
$val | Add-Member -MemberType NoteProperty -Name 'OperationGuid' -Value $OperationGuid -Force
203+
}
204+
} else {
205+
$body.value | Add-Member -MemberType NoteProperty -Name 'OperationGuid' -Value $OperationGuid -Force
206+
}
207+
}
208+
} else {
209+
# Create success indicators when GUID was provided (caller wants tracking)
210+
if ($OperationGuid) {
211+
$body | Add-Member -MemberType NoteProperty -Name 'value' -Value ([pscustomobject]@{
212+
Success = $true
213+
OperationGuid = $OperationGuid
214+
}) -Force
215+
}
216+
}
144217
}
145218
$body.value
146219
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardActivityBasedTimeout.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ function Invoke-CIPPStandardActivityBasedTimeout {
4343
Return
4444
}
4545

46-
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $Tenant
46+
try {
47+
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $Tenant
48+
}
49+
catch {
50+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
51+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the ActivityBasedTimeout state for $Tenant. Error: $ErrorMessage" -Sev Error
52+
return
53+
}
4754
$StateIsCorrect = if ($CurrentState.definition -like "*$timeout*") { $true } else { $false }
4855

4956
If ($Settings.remediate -eq $true) {

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAnonReportDisable.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ function Invoke-CIPPStandardAnonReportDisable {
3131
param($Tenant, $Settings)
3232
#$Rerun -Type Standard -Tenant $Tenant -API 'allowOTPTokens' -Settings $Settings
3333

34-
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/admin/reportSettings' -tenantid $Tenant -AsApp $true
34+
try {
35+
$CurrentInfo = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/admin/reportSettings' -tenantid $Tenant -AsApp $true
36+
}
37+
catch {
38+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
39+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the AnonReportDisable state for $Tenant. Error: $ErrorMessage" -Sev Error
40+
return
41+
}
3542

3643
If ($Settings.remediate -eq $true) {
3744

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAuthMethodsPolicyMigration.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ function Invoke-CIPPStandardAuthMethodsPolicyMigration {
2828
#>
2929

3030
param($Tenant, $Settings)
31-
$CurrentInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/policies/authenticationMethodsPolicy' -tenantid $Tenant
31+
try {
32+
$CurrentInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/policies/authenticationMethodsPolicy' -tenantid $Tenant
33+
}
34+
catch {
35+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
36+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the AuthMethodsPolicyMigration state for $Tenant. Error: $ErrorMessage" -Sev Error
37+
return
38+
}
3239

3340
if ($null -eq $CurrentInfo) {
3441
throw "Failed to retrieve current authentication methods policy information"

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAutoAddProxy.ps1

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ function Invoke-CIPPStandardAutoAddProxy {
3535
$QueueItem
3636
)
3737

38-
$Domains = New-ExoRequest -TenantId $Tenant -Cmdlet 'Get-AcceptedDomain' | Select-Object -ExpandProperty DomainName
39-
$AllMailboxes = New-ExoRequest -TenantId $Tenant -Cmdlet 'Get-Mailbox'
40-
38+
try {
39+
$Domains = New-ExoRequest -TenantId $Tenant -Cmdlet 'Get-AcceptedDomain' | Select-Object -ExpandProperty DomainName
40+
$AllMailboxes = New-ExoRequest -TenantId $Tenant -Cmdlet 'Get-Mailbox'
41+
}
42+
catch {
43+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
44+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the AutoAddProxy state for $Tenant. Error: $ErrorMessage" -Sev Error
45+
return
46+
}
47+
4148
$MissingProxies = 0
4249
foreach ($Domain in $Domains) {
4350
$ProcessMailboxes = $AllMailboxes | Where-Object {
@@ -47,15 +54,15 @@ function Invoke-CIPPStandardAutoAddProxy {
4754
}
4855
$MissingProxies += $ProcessMailboxes.Count
4956
}
50-
57+
5158
$StateIsCorrect = $MissingProxies -eq 0
52-
59+
5360
if ($Settings.report -eq $true) {
5461
$state = $StateIsCorrect ? $true : $MissingProxies
5562
Set-CIPPStandardsCompareField -FieldName 'standards.AutoAddProxy' -FieldValue $state -TenantFilter $Tenant
5663
Add-CIPPBPAField -FieldName 'AutoAddProxy' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
5764
}
58-
65+
5966
if ($Settings.alert -eq $true) {
6067
if ($StateIsCorrect -eq $true) {
6168
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'All mailboxes have proxy addresses for all domains' -sev Info

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAutoExpandArchive.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ function Invoke-CIPPStandardAutoExpandArchive {
3636
} #we're done.
3737
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'AutoExpandArchive'
3838

39-
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').AutoExpandingArchiveEnabled
39+
try {
40+
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').AutoExpandingArchiveEnabled
41+
}
42+
catch {
43+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
44+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the AutoExpandArchive state for $Tenant. Error: $ErrorMessage" -Sev Error
45+
return
46+
}
4047

4148
If ($Settings.remediate -eq $true) {
4249
Write-Host 'Time to remediate'

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardBookings.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ function Invoke-CIPPStandardBookings {
4040
# Get state value using null-coalescing operator
4141
$state = $Settings.state.value ?? $Settings.state
4242

43-
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').BookingsEnabled
43+
try {
44+
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig').BookingsEnabled
45+
}
46+
catch {
47+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
48+
Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the Bookings state for $Tenant. Error: $ErrorMessage" -Sev Error
49+
return
50+
}
4451
$WantedState = if ($state -eq 'true') { $true } else { $false }
4552
$StateIsCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false }
4653

0 commit comments

Comments
 (0)