diff --git a/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 b/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 index 80fd965ad859..20620029e0e9 100644 --- a/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 +++ b/Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1 @@ -66,6 +66,8 @@ function Get-GraphRequestList { [string]$ReverseTenantLookupProperty = 'tenantId' ) + $SingleTenantThreshold = 8000 + $TableName = ('cache{0}' -f ($Endpoint -replace '[^A-Za-z0-9]'))[0..62] -join '' Write-Information "Table: $TableName" $Endpoint = $Endpoint -replace '^/', '' @@ -86,39 +88,64 @@ function Get-GraphRequestList { $GraphQuery.Query = $ParamCollection.ToString() $PartitionKey = Get-StringHash -String (@($Endpoint, $ParamCollection.ToString()) -join '-') Write-Information "PK: $PartitionKey" - Write-Information ( 'GET [ {0} ]' -f $GraphQuery.ToString()) + # Perform $count check before caching + $Count = 0 + if ($TenantFilter -ne 'AllTenants') { + $GraphRequest = @{ + uri = $GraphQuery.ToString() + tenantid = $TenantFilter + ComplexFilter = $true + } + + if ($NoPagination.IsPresent) { + $GraphRequest.noPagination = $NoPagination.IsPresent + } + if ($CountOnly.IsPresent) { + $GraphRequest.CountOnly = $CountOnly.IsPresent + } + if ($NoAuthCheck.IsPresent) { + $GraphRequest.noauthcheck = $NoAuthCheck.IsPresent + } + if ($Parameters.'$count' -and !$SkipCache.IsPresent -and !$NoPagination.IsPresent) { + $Count = New-GraphGetRequest @GraphRequest -CountOnly -ErrorAction Stop + if ($CountOnly.IsPresent) { return $Count } + Write-Information "Total results (`$count): $Count" + } + } + try { if ($QueueId) { $Table = Get-CIPPTable -TableName $TableName $Filter = "QueueId eq '{0}'" -f $QueueId $Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter $Type = 'Queue' - } elseif ($TenantFilter -eq 'AllTenants' -or (!$SkipCache.IsPresent -and !$ClearCache.IsPresent -and !$CountOnly.IsPresent)) { - $Table = Get-CIPPTable -TableName $TableName - $Timestamp = (Get-Date).AddHours(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffK') - if ($TenantFilter -eq 'AllTenants') { - $Filter = "PartitionKey eq '{0}' and QueueType eq 'AllTenants' and Timestamp ge datetime'{1}'" -f $PartitionKey, $Timestamp - } else { - $Filter = "PartitionKey eq '{0}' and Tenant eq '{1}' and Timestamp ge datetime'{2}'" -f $PartitionKey, $TenantFilter, $Timestamp + Write-Information "Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))" + $QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey + $RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' } + } elseif (!$SkipCache.IsPresent -and !$ClearCache.IsPresent -and !$CountOnly.IsPresent) { + if ($TenantFilter -eq 'AllTenants' -or $Count -gt $SingleTenantThreshold) { + $Table = Get-CIPPTable -TableName $TableName + $Timestamp = (Get-Date).AddHours(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffK') + if ($TenantFilter -eq 'AllTenants') { + $Filter = "PartitionKey eq '{0}' and QueueType eq 'AllTenants' and Timestamp ge datetime'{1}'" -f $PartitionKey, $Timestamp + } else { + $Filter = "PartitionKey eq '{0}' and Tenant eq '{1}' and Timestamp ge datetime'{2}'" -f $PartitionKey, $TenantFilter, $Timestamp + } + $Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter + $Type = 'Cache' + Write-Information "Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))" + $QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey + $RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' } } - #Write-Information $Filter - $Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter - $Type = 'Cache' - } else { - $Type = 'None' - $Rows = @() } - Write-Information "Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))" - - $QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey - $RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' } } catch { Write-Information $_.InvocationInfo.PositionMessage } if ($TenantFilter -ne 'AllTenants' -and $Endpoint -match '%tenantid%') { + Write-Information "Replacing TenantId in endpoint with $TenantFilter" $TenantId = (Get-Tenants -IncludeErrors | Where-Object { $_.defaultDomainName -eq $TenantFilter -or $_.customerId -eq $TenantFilter }).customerId $Endpoint = $Endpoint -replace '%tenantid%', $TenantId $GraphQuery = [System.UriBuilder]('https://graph.microsoft.com/{0}/{1}' -f $Version, $Endpoint) @@ -127,6 +154,7 @@ function Get-GraphRequestList { $ParamCollection.Add($Item.Key, $Item.Value) } $GraphQuery.Query = $ParamCollection.ToString() + $GraphRequest.uri = $GraphQuery.ToString() } if (!$Rows) { @@ -208,31 +236,10 @@ function Get-GraphRequestList { } } default { - $GraphRequest = @{ - uri = $GraphQuery.ToString() - tenantid = $TenantFilter - ComplexFilter = $true - } - - if ($NoPagination.IsPresent) { - $GraphRequest.noPagination = $NoPagination.IsPresent - } - - if ($CountOnly.IsPresent) { - $GraphRequest.CountOnly = $CountOnly.IsPresent - } - - if ($NoAuthCheck.IsPresent) { - $GraphRequest.noauthcheck = $NoAuthCheck.IsPresent - } - try { $QueueThresholdExceeded = $false if ($Parameters.'$count' -and !$SkipCache -and !$NoPagination) { - $Count = New-GraphGetRequest @GraphRequest -CountOnly -ErrorAction Stop - if ($CountOnly.IsPresent) { return $Count } - Write-Information "Total results (`$count): $Count" - if ($Count -gt 8000) { + if ($Count -gt $singleTenantThreshold) { $QueueThresholdExceeded = $true if ($RunningQueue) { Write-Information 'Queue currently running' diff --git a/Modules/CIPPCore/Public/Standards/Get-CIPPStandards.ps1 b/Modules/CIPPCore/Public/Standards/Get-CIPPStandards.ps1 index 5b73e19eae98..60751d34303d 100644 --- a/Modules/CIPPCore/Public/Standards/Get-CIPPStandards.ps1 +++ b/Modules/CIPPCore/Public/Standards/Get-CIPPStandards.ps1 @@ -76,12 +76,13 @@ function Get-CIPPStandards { } } } - } - foreach ($Standard in $ComputedStandards.Keys) { - [pscustomobject]@{ - Tenant = $Tenant.defaultDomainName - Standard = $Standard - Settings = $ComputedStandards.$Standard + + foreach ($Standard in $ComputedStandards.Keys) { + [pscustomobject]@{ + Tenant = $Tenant.defaultDomainName + Standard = $Standard + Settings = $ComputedStandards.$Standard + } } } } diff --git a/Modules/CippExtensions/NinjaOne/Get-NinjaOneOrgMapping.ps1 b/Modules/CippExtensions/NinjaOne/Get-NinjaOneOrgMapping.ps1 index 8f9e3d89936b..a0274cb0d16f 100644 --- a/Modules/CippExtensions/NinjaOne/Get-NinjaOneOrgMapping.ps1 +++ b/Modules/CippExtensions/NinjaOne/Get-NinjaOneOrgMapping.ps1 @@ -13,14 +13,14 @@ function Get-NinjaOneOrgMapping { $Mappings | Add-Member -NotePropertyName $_.RowKey -NotePropertyValue @{ label = "$($_.NinjaOneName)"; value = "$($_.NinjaOne)" } } #Get Available Tenants - + #Get available Ninja clients $Table = Get-CIPPTable -TableName Extensionsconfig $Configuration = ((Get-AzDataTableEntity @Table).config | ConvertFrom-Json -ea stop).NinjaOne - - + + $Token = Get-NinjaOneToken -configuration $Configuration - + $After = 0 $PageSize = 1000 $NinjaOrgs = do { @@ -29,16 +29,16 @@ function Get-NinjaOneOrgMapping { $ResultCount = ($Result.id | Measure-Object -Maximum) $After = $ResultCount.maximum - } while ($ResultCount.count -eq $PageSize) - + } while ($ResultCount.count -eq $PageSize) + } catch { $Message = if ($_.ErrorDetails.Message) { Get-NormalizedError -Message $_.ErrorDetails.Message } else { $_.Exception.message } - - $NinjaOrgs = @(@{ name = $Message }) + + $NinjaOrgs = @(@{ name = 'Could not get NinjaOne Orgs, check your API credentials and try again.'; value = '-1' }) } $MappingObj = [PSCustomObject]@{ diff --git a/Modules/CippExtensions/Private/Get-HaloMapping.ps1 b/Modules/CippExtensions/Private/Get-HaloMapping.ps1 index 8391252ae065..fcae99cfd5d1 100644 --- a/Modules/CippExtensions/Private/Get-HaloMapping.ps1 +++ b/Modules/CippExtensions/Private/Get-HaloMapping.ps1 @@ -32,7 +32,7 @@ function Get-HaloMapping { } Write-LogMessage -Message "Could not get HaloPSA Clients, error: $Message " -Level Error -tenant 'CIPP' -API 'HaloMapping' - $RawHaloClients = @(@{name = "Could not get HaloPSA Clients, error: $Message" }) + $RawHaloClients = @(@{name = "Could not get HaloPSA Clients, error: $Message"; value = '-1' }) } $HaloClients = $RawHaloClients | ForEach-Object { [PSCustomObject]@{ diff --git a/Scheduler_GetQueue/run.ps1 b/Scheduler_GetQueue/run.ps1 index 87d355d1476c..f58f9d667ea6 100644 --- a/Scheduler_GetQueue/run.ps1 +++ b/Scheduler_GetQueue/run.ps1 @@ -21,7 +21,7 @@ $Tasks = foreach ($Tenant in $Tenants) { Tag = 'AllTenants' TenantID = $t.customerId Type = $Tenant.type - RowKey = $Tenant.RowKey + RowKey = $t.RowKey } } } diff --git a/version_latest.txt b/version_latest.txt index 262122f6796a..722fb619cef4 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -5.7.1 \ No newline at end of file +5.7.2 \ No newline at end of file