1
1
using namespace System.Net
2
2
3
- Function Invoke-ListLogs {
3
+ function Invoke-ListLogs {
4
4
<#
5
5
. FUNCTIONALITY
6
6
Entrypoint
@@ -25,17 +25,35 @@ Function Invoke-ListLogs {
25
25
}
26
26
} else {
27
27
if ($request.Query.Filter -eq ' True' ) {
28
- $LogLevel = if ($Request.query .Severity ) { ($Request.query.Severity ).split(' ,' ) } else { ' Info' , ' Warn' , ' Error' , ' Critical' , ' Alert' }
29
- $PartitionKey = $Request.query .DateFilter
28
+ $LogLevel = if ($Request.Query .Severity ) { ($Request.query.Severity ).split(' ,' ) } else { ' Info' , ' Warn' , ' Error' , ' Critical' , ' Alert' }
29
+ $PartitionKey = $Request.Query .DateFilter
30
30
$username = $Request.Query.User
31
+
32
+ $StartDate = $Request.Query.StartDate ?? $Request.Query.DateFilter
33
+ $EndDate = $Request.Query.EndDate ?? $Request.Query.DateFilter
34
+
35
+ if ($StartDate -and $EndDate ) {
36
+ # Collect logs for each partition key date in range
37
+ $PartitionKeys = for ($Date = [datetime ]::ParseExact($StartDate , ' yyyyMMdd' , $null ); $Date -le [datetime ]::ParseExact($EndDate , ' yyyyMMdd' , $null ); $Date = $Date.AddDays (1 )) {
38
+ $PartitionKey = $Date.ToString (' yyyyMMdd' )
39
+ " PartitionKey eq '$PartitionKey '"
40
+ }
41
+ $Filter = $PartitionKeys -join ' or '
42
+ } elseif ($StartDate ) {
43
+ $Filter = " PartitionKey eq '{0}'" -f $StartDate
44
+ } else {
45
+ $Filter = " PartitionKey eq '{0}'" -f (Get-Date - UFormat ' %Y%m%d' )
46
+ }
31
47
} else {
32
48
$LogLevel = ' Info' , ' Warn' , ' Error' , ' Critical' , ' Alert'
33
49
$PartitionKey = Get-Date - UFormat ' %Y%m%d'
34
50
$username = ' *'
51
+ $Filter = " PartitionKey eq '{0}'" -f $PartitionKey
35
52
}
36
53
$AllowedTenants = Test-CIPPAccess - Request $Request - TenantList
37
- $Filter = " PartitionKey eq '{0}'" -f $PartitionKey
38
- $Rows = Get-AzDataTableEntity @Table - Filter $Filter | Where-Object { $_.Severity -In $LogLevel -and $_.user -like $username }
54
+ Write-Host " Getting logs for filter: $Filter , LogLevel: $LogLevel , Username: $username "
55
+
56
+ $Rows = Get-AzDataTableEntity @Table - Filter $Filter | Where-Object { $_.Severity -in $LogLevel -and $_.user -like $username }
39
57
foreach ($Row in $Rows ) {
40
58
if ($AllowedTenants -notcontains ' AllTenants' ) {
41
59
$TenantList = Get-Tenants - IncludeErrors
0 commit comments