Skip to content

Commit e5cb86d

Browse files
committed
Feat: Add option to set password never expires
1 parent dc0df58 commit e5cb86d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Invoke-ExecPasswordNeverExpires {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
6+
.ROLE
7+
Identity.User.ReadWrite
8+
#>
9+
Param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
14+
15+
# Interact with query parameters or the body of the request.
16+
$TenantFilter = $Request.Body.tenantFilter
17+
$UserId = $Request.Body.userId
18+
$UserPrincipalName = $Request.Body.userPrincipalName # Only used for logging
19+
$PasswordPolicy = $Request.Body.PasswordPolicy.value ?? $Request.Body.PasswordPolicy ?? 'None'
20+
$PasswordPolicyName = $Request.Body.PasswordPolicy.label ?? $Request.Body.PasswordPolicy.value ?? $Request.Body.PasswordPolicy # Only used for logging
21+
22+
if ([string]::IsNullOrWhiteSpace($UserId)) { exit }
23+
try {
24+
$Body = ConvertTo-Json -InputObject @{ passwordPolicies = $PasswordPolicy } -Depth 5 -Compress
25+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/users/$UserId" -tenantid $TenantFilter -Body $Body -type PATCH
26+
$Result = "Successfully set PasswordPolicy for user $UserPrincipalName to $PasswordPolicyName"
27+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Info
28+
$StatusCode = [HttpStatusCode]::OK
29+
} catch {
30+
$ErrorMessage = Get-CippException -Exception $_
31+
$Result = "Failed to set PasswordPolicy for user $UserPrincipalName to $PasswordPolicyName. Error: $($ErrorMessage.NormalizedError)"
32+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev Error -LogData $ErrorMessage
33+
$StatusCode = [HttpStatusCode]::InternalServerError
34+
}
35+
36+
# Associate values to output bindings by calling 'Push-OutputBinding'.
37+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
38+
StatusCode = $StatusCode
39+
Body = @{ 'Results' = @($Result) }
40+
})
41+
}

0 commit comments

Comments
 (0)