Skip to content

Commit bd6aa3e

Browse files
committed
Refactor New-CIPPTAP to return object thats better to copy in the frontend, while adding properties to make API module ease of use better
1 parent effedec commit bd6aa3e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Modules/CIPPCore/Public/New-CIPPTAP.ps1

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ function New-CIPPTAP {
1010
try {
1111
$GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($userid)/authentication/temporaryAccessPassMethods" -tenantid $TenantFilter -type POST -body '{}' -verbose
1212
Write-LogMessage -headers $Headers -API $APIName -message "Created Temporary Access Password (TAP) for $userid" -Sev 'Info' -tenant $TenantFilter
13-
$Results = [System.Collections.Generic.List[string]]::new()
14-
$Results.Add("The TAP for this user is $($GraphRequest.temporaryAccessPass) - This TAP is usable for the next $($GraphRequest.LifetimeInMinutes) minutes")
15-
$Results.Add("$($GraphRequest.temporaryAccessPass)")
16-
return $Results
13+
return @{
14+
resultText = "The TAP for this user is $($GraphRequest.temporaryAccessPass) - This TAP is usable for the next $($GraphRequest.LifetimeInMinutes) minutes"
15+
copyField = $GraphRequest.temporaryAccessPass
16+
temporaryAccessPass = $GraphRequest.temporaryAccessPass
17+
lifetimeInMinutes = $GraphRequest.LifetimeInMinutes
18+
startDateTime = $GraphRequest.startDateTime
19+
state = 'success'
20+
}
1721

1822
} catch {
1923
$ErrorMessage = Get-CippException -Exception $_
2024
$Result = "Failed to create Temporary Access Password (TAP) for $($userid): $($ErrorMessage.NormalizedError)"
2125
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
22-
throw @{ Results = $Result }
23-
24-
26+
throw $Result
2527
}
26-
2728
}
2829

0 commit comments

Comments
 (0)