@@ -17,7 +17,8 @@ function Invoke-ExecJITAdmin {
17
17
18
18
if ($Request.Query.Action -eq ' List' ) {
19
19
$Schema = Get-CIPPSchemaExtensions | Where-Object { $_.id -match ' _cippUser' } | Select-Object - First 1
20
- if ($TenantFilter -ne ' AllTenants' ) {
20
+ if ($Request.Query.TenantFilter -ne ' AllTenants' ) {
21
+ # Single tenant logic
21
22
$Query = @ {
22
23
TenantFilter = $Request.Query.TenantFilter
23
24
Endpoint = ' users'
@@ -36,7 +37,6 @@ function Invoke-ExecJITAdmin {
36
37
}
37
38
)
38
39
}
39
- # Use $TenantFilter consistently, which is derived from Body or Query params at line 15
40
40
$RoleResults = New-GraphBulkRequest - tenantid $Request.Query.TenantFilter - Requests @ ($BulkRequests )
41
41
# Write-Information ($RoleResults | ConvertTo-Json -Depth 10 )
42
42
$Results = $Users | ForEach-Object {
@@ -63,34 +63,30 @@ function Invoke-ExecJITAdmin {
63
63
# AllTenants logic
64
64
$Results = [System.Collections.Generic.List [object ]]::new()
65
65
$Metadata = @ {}
66
- # Assumed table name for JIT Admin cache. User might need to adjust.
67
66
$Table = Get-CIPPTable - TableName CacheJITAdmin
68
- $PartitionKey = ' JITAdminUsers' # Assumed partition key
69
-
70
- # Filter for recent data, e.g., last 60 minutes. Orchestrator populates this.
67
+ $PartitionKey = ' JITAdminUser'
71
68
$Filter = " PartitionKey eq '$PartitionKey '"
72
- $Rows = Get-CIPPAzDataTableEntity @Table - filter $Filter | Where-Object - Property Timestamp -GT (Get-Date ).AddMinutes(-1 )
69
+ $Rows = Get-CIPPAzDataTableEntity @Table - filter $Filter | Where-Object - Property Timestamp -GT (Get-Date ).AddMinutes(-60 )
73
70
74
71
$QueueReference = ' {0}-{1}' -f $Request.Query.TenantFilter , $PartitionKey # $TenantFilter is 'AllTenants'
72
+ Write-Information " QueueReference: $QueueReference "
75
73
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -notmatch ' Completed' -and $_.Status -notmatch ' Failed' }
76
74
77
75
if ($RunningQueue ) {
78
76
$Metadata = [PSCustomObject ]@ {
79
77
QueueMessage = ' Still loading JIT Admin data for all tenants. Please check back in a few more minutes.'
80
78
}
81
- $Results.Add ([PSCustomObject ]@ { Waiting = $true })
82
- } elseif (! $dRows -and ! $RunningQueue ) {
79
+ } elseif (! $Rows -and ! $RunningQueue ) {
83
80
$TenantList = Get-Tenants - IncludeErrors
84
- $QueueLink = if ($Request.RequestUri ) { $Request.RequestUri.ToString () -replace $Request.Query.Action , ' List' } else { ' /identity/administration/users/jit-admin?Action=List&TenantFilter=AllTenants' } # Fallback link
85
- $Queue = New-CippQueueEntry - Name ' JIT Admin List - All Tenants' - Link $QueueLink - Reference $QueueReference - TotalTasks ($TenantList | Measure-Object ).Count
81
+ $Queue = New-CippQueueEntry - Name ' JIT Admin List - All Tenants' - Link ' /identity/administration/jit-admin?tenantFilter=AllTenants' - Reference $QueueReference - TotalTasks ($TenantList | Measure-Object ).Count
86
82
87
83
$Metadata = [PSCustomObject ]@ {
88
84
QueueMessage = ' Loading JIT Admin data for all tenants. Please check back in a few minutes.'
89
85
}
90
86
$InputObject = [PSCustomObject ]@ {
91
- OrchestratorName = ' JITAdminListAllTenantsOrchestrator ' # Assumed orchestrator name
87
+ OrchestratorName = ' JITAdminOrchestrator '
92
88
QueueFunction = @ {
93
- FunctionName = ' GetTenants' # Generic entry, durable function handles per-tenant logic
89
+ FunctionName = ' GetTenants'
94
90
QueueId = $Queue.RowKey
95
91
TenantParams = @ {
96
92
IncludeErrors = $true
@@ -100,32 +96,24 @@ function Invoke-ExecJITAdmin {
100
96
SkipLog = $true
101
97
}
102
98
Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
103
- $Results.Add ([PSCustomObject ]@ { Waiting = $true })
104
99
} else {
105
- # $dRows exist
100
+ # There is data in the cache, so we will use that
101
+ Write-Information " Found $ ( $Rows.Count ) rows in the cache"
106
102
foreach ($row in $Rows ) {
107
- # Assuming $row.JITUserObject contains the serialized PSCustomObject for the user's JIT details
108
- # And $row.TenantId (or $row.TenantDisplayName) contains the tenant identifier
109
- try {
110
- $UserObject = $row.JITUserObject | ConvertFrom-Json
111
- $Results.Add (
112
- [PSCustomObject ]@ {
113
- Tenant = $row.TenantId # Or TenantDisplayName, ensure orchestrator stores this
114
- id = $UserObject.id
115
- displayName = $UserObject.displayName
116
- userPrincipalName = $UserObject.userPrincipalName
117
- accountEnabled = $UserObject.accountEnabled
118
- jitAdminEnabled = $UserObject.jitAdminEnabled
119
- jitAdminExpiration = $UserObject.jitAdminExpiration
120
- memberOf = $UserObject.memberOf # This should be an array of role objects
121
- }
122
- )
123
- } catch {
124
- Write-LogMessage - Headers $User - API $APIName - message " Failed to process cached JIT admin row for Tenant $ ( $row.TenantId ) , RowKey $ ( $row.RowKey ) . Error: $ ( $_.Exception.Message ) " - Sev ' Warning'
125
- # Optionally add a placeholder or skip if critical
126
- }
103
+ $UserObject = $row.JITAdminUser | ConvertFrom-Json
104
+ $Results.Add (
105
+ [PSCustomObject ]@ {
106
+ Tenant = $row.Tenant
107
+ id = $UserObject.id
108
+ displayName = $UserObject.displayName
109
+ userPrincipalName = $UserObject.userPrincipalName
110
+ accountEnabled = $UserObject.accountEnabled
111
+ jitAdminEnabled = $UserObject.jitAdminEnabled
112
+ jitAdminExpiration = $UserObject.jitAdminExpiration
113
+ memberOf = $UserObject.memberOf
114
+ }
115
+ )
127
116
}
128
- $Metadata = @ { Info = ' Displaying cached JIT Admin data for all tenants.' }
129
117
}
130
118
$Body = @ {
131
119
Results = @ ($Results )
0 commit comments