diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-GetCippAlerts.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-GetCippAlerts.ps1 index c236a2bdd5ad..cfdb1ffcd885 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-GetCippAlerts.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-GetCippAlerts.ps1 @@ -19,7 +19,7 @@ function Invoke-GetCippAlerts { $PartitionKey = Get-Date -UFormat '%Y%m%d' $Filter = "PartitionKey eq '{0}'" -f $PartitionKey $Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Sort-Object TableTimestamp -Descending | Select-Object -First 10 - $Role = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Request.Headers.'x-ms-client-principal')) | ConvertFrom-Json).userRoles + $Role = Get-CippAccessRole -Request $Request $CIPPVersion = $Request.Query.localversion $Version = Assert-CippVersion -CIPPVersion $CIPPVersion diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListStandardsCompare.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListStandardsCompare.ps1 index 130cec97dfba..72455cfce276 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListStandardsCompare.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListStandardsCompare.ps1 @@ -14,13 +14,13 @@ function Invoke-ListStandardsCompare { $Table = Get-CIPPTable -TableName 'CippStandardsReports' $TenantFilter = $Request.Query.tenantFilter if ($TenantFilter) { - $Table.Filter = "RowKey eq '{0}'" -f $TenantFilter + $Table.Filter = "PartitionKey eq '{0}'" -f $TenantFilter } - $Results = Get-CIPPAzDataTableEntity @Table + $Standards = Get-CIPPAzDataTableEntity @Table #in the results we have objects starting with "standards." All these have to be converted from JSON. Do not do this is its a boolean - $Results | ForEach-Object { + <#$Results | ForEach-Object { $Object = $_ $Object.PSObject.Properties | ForEach-Object { if ($_.Name -like 'standards_*') { @@ -40,8 +40,43 @@ function Invoke-ListStandardsCompare { $object.PSObject.Properties.Remove($_.Name) } } + }#> + + $TenantStandards = @{} + $Results = [System.Collections.Generic.List[object]]::new() + + foreach ($Standard in $Standards) { + # each standard is on their own row now, the field name is the RowKey and the value is in the Value field + $FieldName = $Standard.RowKey + $FieldValue = $Standard.Value + $Tenant = $Standard.PartitionKey + if ($FieldValue -is [System.Boolean]) { + $FieldValue = [bool]$FieldValue + } elseif ($FieldValue -like '*{*') { + $FieldValue = ConvertFrom-Json -InputObject $FieldValue -ErrorAction SilentlyContinue + } else { + $FieldValue = [string]$FieldValue + } + + if (-not $TenantStandards.ContainsKey($Tenant)) { + $TenantStandards[$Tenant] = @{} + } + $TenantStandards[$Tenant][$FieldName] = @{ + Value = $FieldValue + LastRefresh = $Standard.TimeStamp.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ') + } } + foreach ($Tenant in $TenantStandards.Keys) { + $TenantStandard = [PSCustomObject]@{ + tenantFilter = $Tenant + } + foreach ($Field in $TenantStandards[$Tenant].Keys) { + $Value = $TenantStandards[$Tenant][$Field] + $TenantStandard | Add-Member -MemberType NoteProperty -Name $Field -Value $Value -Force + } + $Results.Add($TenantStandard) + } Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ StatusCode = [HttpStatusCode]::OK diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1 index ba4abdb48e30..258ce05cc801 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1 @@ -28,18 +28,20 @@ function Invoke-listStandardTemplates { Write-Host "$($RowKey) standard could not be loaded: $($_.Exception.Message)" return } - $Data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.GUID -Force - - if (!$Data.excludedTenants) { - $Data | Add-Member -NotePropertyName 'excludedTenants' -NotePropertyValue @() -Force - } - - if ($Data.excludedTenants -and $Data.excludedTenants -ne 'excludedTenants') { - $Data.excludedTenants = @($Data.excludedTenants) - } else { - $Data.excludedTenants = @() + if ($Data) { + $Data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $_.GUID -Force + + if (!$Data.excludedTenants) { + $Data | Add-Member -NotePropertyName 'excludedTenants' -NotePropertyValue @() -Force + } else { + if ($Data.excludedTenants -and $Data.excludedTenants -ne 'excludedTenants') { + $Data.excludedTenants = @($Data.excludedTenants) + } else { + $Data.excludedTenants = @() + } + } + $Data } - $Data } | Sort-Object -Property templateName if ($ID) { $Templates = $Templates | Where-Object GUID -EQ $ID } diff --git a/Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-AuditLogSearchCreation.ps1 b/Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-AuditLogSearchCreation.ps1 index 28919fe56f95..ce3cb766f8fb 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-AuditLogSearchCreation.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-AuditLogSearchCreation.ps1 @@ -9,7 +9,11 @@ function Start-AuditLogSearchCreation { $ConfigTable = Get-CippTable -TableName 'WebhookRules' $ConfigEntries = Get-CIPPAzDataTableEntity @ConfigTable -Filter "PartitionKey eq 'Webhookv2'" | ForEach-Object { $ConfigEntry = $_ - $ConfigEntry.excludedTenants = $ConfigEntry.excludedTenants | ConvertFrom-Json + if (!$ConfigEntry.excludedTenants) { + $ConfigEntry | Add-Member -MemberType NoteProperty -Name 'excludedTenants' -Value @() -Force + } else { + $ConfigEntry.excludedTenants = $ConfigEntry.excludedTenants | ConvertFrom-Json + } $ConfigEntry.Tenants = $ConfigEntry.Tenants | ConvertFrom-Json $ConfigEntry } diff --git a/Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1 b/Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1 index a3d1aef9891b..96c23dbc9fc6 100644 --- a/Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1 +++ b/Modules/CIPPCore/Public/Set-CIPPStandardsCompareField.ps1 @@ -1,19 +1,15 @@ function Set-CIPPStandardsCompareField { + [CmdletBinding(SupportsShouldProcess = $true)] param ( $FieldName, $FieldValue, $TenantFilter ) $Table = Get-CippTable -tablename 'CippStandardsReports' - $TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Tenant - - # Sanitize invalid c#/xml characters for Azure Tables - $FieldName = $FieldName.replace('standards.', 'standards_') - $FieldName = $FieldName.replace('IntuneTemplate.', 'IntuneTemplate_') - $FieldName = $FieldName -replace '-', '__' + $TenantName = Get-Tenants -TenantFilter $TenantFilter if ($FieldValue -is [System.Boolean]) { - $fieldValue = [bool]$FieldValue + $FieldValue = [bool]$FieldValue } elseif ($FieldValue -is [string]) { $FieldValue = [string]$FieldValue } else { @@ -21,29 +17,24 @@ function Set-CIPPStandardsCompareField { $FieldValue = [string]$FieldValue } - $Existing = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'StandardReport' and RowKey eq '$($TenantName.defaultDomainName)'" - try { - if ($Existing) { - $Existing = $Existing | Select-Object * -ExcludeProperty ETag, TimeStamp | ConvertTo-Json -Depth 10 -Compress | ConvertFrom-Json -AsHashtable - $Existing[$FieldName] = $FieldValue - $Existing['LastRefresh'] = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z') - $Existing = [PSCustomObject]$Existing + $Existing = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq '$($TenantName.defaultDomainName)' and RowKey eq '$($FieldName)'" - Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force - } else { - $Result = @{ - tenantFilter = "$($TenantName.defaultDomainName)" - GUID = "$($TenantName.customerId)" - RowKey = "$($TenantName.defaultDomainName)" - PartitionKey = 'StandardReport' - LastRefresh = [string]$(Get-Date (Get-Date).ToUniversalTime() -UFormat '+%Y-%m-%dT%H:%M:%S.000Z') + if ($PSCmdlet.ShouldProcess('CIPP Standards Compare', "Set field '$FieldName' to '$FieldValue' for tenant '$($TenantName.defaultDomainName)'")) { + try { + if ($Existing) { + $Existing.Value = $FieldValue + Add-CIPPAzDataTableEntity @Table -Entity $Existing -Force + } else { + $Result = [PSCustomObject]@{ + PartitionKey = [string]$TenantName.defaultDomainName + RowKey = [string]$FieldName + Value = $FieldValue + } + Add-CIPPAzDataTableEntity @Table -Entity $Result -Force } - $Result[$FieldName] = $FieldValue - Add-CIPPAzDataTableEntity @Table -Entity $Result -Force - + Write-Information "Adding $FieldName to StandardCompare for $Tenant. content is $FieldValue" + } catch { + Write-Warning "Failed to add $FieldName to StandardCompare for $Tenant. content is $FieldValue - $($_.Exception.Message)" } - Write-Information "Adding $FieldName to StandardCompare for $Tenant. content is $FieldValue" - } catch { - Write-Warning "Failed to add $FieldName to StandardCompare for $Tenant. content is $FieldValue - $($_.Exception.Message)" } } diff --git a/Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardGlobalQuarantineNotifications.ps1 b/Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardGlobalQuarantineNotifications.ps1 index 73a674953353..1796526de3ef 100644 --- a/Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardGlobalQuarantineNotifications.ps1 +++ b/Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardGlobalQuarantineNotifications.ps1 @@ -64,7 +64,7 @@ function Invoke-CIPPStandardGlobalQuarantineNotifications { } else { try { if ($CurrentState.Name -eq 'DefaultGlobalPolicy') { - $null = New-ExoRequest -tenantid $Tenant -cmdlet 'New-QuarantinePolicy' -cmdParams @{ Name = 'DefaultGlobalTag'; QuarantinePolicyType = 'GlobalQuarantinePolicy'; EndUserSpamNotificationFrequency = [string]$WantedState.TotalHours } + $null = New-ExoRequest -tenantid $Tenant -cmdlet 'New-QuarantinePolicy' -cmdParams @{ Name = 'DefaultGlobalTag'; QuarantinePolicyType = 'GlobalQuarantinePolicy'; EndUserSpamNotificationFrequency = [string]$WantedState } } else { $null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-QuarantinePolicy' -cmdParams @{Identity = $CurrentState.Identity; EndUserSpamNotificationFrequency = [string]$WantedState } } diff --git a/version_latest.txt b/version_latest.txt index 8b22a322d0fe..215aacb45236 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -8.0.2 +8.0.3