11using namespace System.Net
22
3- Function Invoke-ListLogs {
3+ function Invoke-ListLogs {
44 <#
55 . FUNCTIONALITY
66 Entrypoint
@@ -25,17 +25,35 @@ Function Invoke-ListLogs {
2525 }
2626 } else {
2727 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
3030 $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+ }
3147 } else {
3248 $LogLevel = ' Info' , ' Warn' , ' Error' , ' Critical' , ' Alert'
3349 $PartitionKey = Get-Date - UFormat ' %Y%m%d'
3450 $username = ' *'
51+ $Filter = " PartitionKey eq '{0}'" -f $PartitionKey
3552 }
3653 $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 }
3957 foreach ($Row in $Rows ) {
4058 if ($AllowedTenants -notcontains ' AllTenants' ) {
4159 $TenantList = Get-Tenants - IncludeErrors
0 commit comments