Skip to content

Commit 2ad0dcf

Browse files
db request add type
1 parent e9576d3 commit 2ad0dcf

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Modules/CIPPCore/Public/New-CIPPDbRequest.ps1

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,38 @@ function New-CIPPDbRequest {
99
.PARAMETER TenantFilter
1010
The tenant domain or GUID to filter by (used as partition key)
1111
12+
.PARAMETER Type
13+
Optional. The data type to filter by (e.g., Users, Groups, Devices)
14+
1215
.EXAMPLE
1316
New-CIPPDbRequest -TenantFilter 'contoso.onmicrosoft.com'
17+
18+
.EXAMPLE
19+
New-CIPPDbRequest -TenantFilter 'contoso.onmicrosoft.com' -Type 'Users'
1420
#>
1521
[CmdletBinding()]
1622
param(
1723
[Parameter(Mandatory = $true)]
18-
[string]$TenantFilter
24+
[string]$TenantFilter,
25+
26+
[Parameter(Mandatory = $false)]
27+
[string]$Type
1928
)
2029

2130
try {
2231
$Table = Get-CippTable -tablename 'CippReportingDB'
23-
$Filter = "PartitionKey eq '{0}'" -f $TenantFilter
32+
33+
if ($Type) {
34+
$Filter = "PartitionKey eq '{0}' and RowKey ge '{1}-' and RowKey lt '{1}.'" -f $TenantFilter, $Type
35+
} else {
36+
$Filter = "PartitionKey eq '{0}'" -f $TenantFilter
37+
}
38+
2439
$Results = Get-CIPPAzDataTableEntity @Table -Filter $Filter
2540

26-
return $Results
41+
return ($Results.Data | ConvertFrom-Json -ErrorAction SilentlyContinue)
2742
} catch {
28-
Write-LogMessage -API 'CIPPDbRequest' -tenant $TenantFilter `
29-
-message "Failed to query database: $($_.Exception.Message)" -sev Error
43+
Write-LogMessage -API 'CIPPDbRequest' -tenant $TenantFilter -message "Failed to query database: $($_.Exception.Message)" -sev Error
3044
throw
3145
}
3246
}

0 commit comments

Comments
 (0)