Skip to content

Commit e419c72

Browse files
committed
Increase retry limit for TAP creation to 10 attempts for improved reliability
1 parent 12082a7 commit e419c72

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ExecJITAdmin.ps1

+5-4
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,19 @@ Function Invoke-ExecJITAdmin {
103103
$TapBody = '{}'
104104
}
105105
Write-Information "https://graph.microsoft.com/beta/users/$Username/authentication/temporaryAccessPassMethods"
106-
# Retry creating the TAP up to 5 times, since it can fail due to the user not being fully created yet
106+
# Retry creating the TAP up to 10 times, since it can fail due to the user not being fully created yet. Sometimes it takes 2 reties, sometimes it takes 8+. Very annoying. -Bobby
107107
$Retries = 0
108+
$MAX_TAP_RETRIES = 10
108109
do {
109110
try {
110111
$TapRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($Username)/authentication/temporaryAccessPassMethods" -tenantid $TenantFilter -type POST -body $TapBody
111112
} catch {
112113
Start-Sleep -Seconds 2
113-
Write-Information 'ERROR: Failed to create TAP, retrying'
114-
Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
114+
Write-Information "ERROR: Run $Retries of $MAX_TAP_RETRIES : Failed to create TAP, retrying"
115+
# Write-Information ( ConvertTo-Json -Depth 5 -InputObject (Get-CippException -Exception $_))
115116
}
116117
$Retries++
117-
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le 5 )
118+
} while ( $null -eq $TapRequest.temporaryAccessPass -and $Retries -le $MAX_TAP_RETRIES )
118119

119120
$TempPass = $TapRequest.temporaryAccessPass
120121
$PasswordExpiration = $TapRequest.LifetimeInMinutes

0 commit comments

Comments
 (0)