Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warnings for enable/disable and password reset on AD synced users #985

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Modules/CIPPCore/Public/Set-CIPPResetPassword.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function Set-CIPPResetPassword {
}
} | ConvertTo-Json -Compress

$UserDetails = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users/$($UserId)?`$select=onPremisesSyncEnabled" -noPagination $true -tenantid $TenantFilter -verbose
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/users/$($userid)" -tenantid $TenantFilter -type PATCH -body $passwordProfile -verbose

#PWPush
Expand All @@ -25,7 +26,12 @@ function Set-CIPPResetPassword {
$password = $PasswordLink
}
Write-LogMessage -user $ExecutingUser -API $APIName -message "Reset the password for $($userid). User must change password is set to $forceChangePasswordNextSignIn" -Sev 'Info' -tenant $TenantFilter
return "Reset the password for $($userid). User must change password is set to $forceChangePasswordNextSignIn. The new password is $password"

if($UserDetails.onPremisesSyncEnabled -eq $true){
return "Reset the password for $($userid). User must change password is set to $forceChangePasswordNextSignIn. The new password is $password. WARNING: This user is AD synced. Please confirm passthrough or writeback is enabled."
}else{
return "Reset the password for $($userid). User must change password is set to $forceChangePasswordNextSignIn. The new password is $password"
}
} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not reset password for $($userid). Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
Expand Down
10 changes: 8 additions & 2 deletions Modules/CIPPCore/Public/Set-CIPPSignInState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ function Set-CIPPSignInState {
accountEnabled = [bool]$AccountEnabled
}
$body = ConvertTo-Json -InputObject $body -Compress -Depth 5
$UserDetails = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/users/$($UserId)?`$select=onPremisesSyncEnabled" -noPagination $true -tenantid $TenantFilter -verbose
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/v1.0/users/$($UserId)" -tenantid $TenantFilter -type PATCH -body $body -verbose
Write-LogMessage -user $ExecutingUser -API $APIName -message "Set account enabled state to $AccountEnabled for $UserId" -Sev 'Info' -tenant $TenantFilter
return "Set account enabled state to $AccountEnabled for $UserId"

if($UserDetails.onPremisesSyncEnabled -eq $true){
return "WARNING: User is AD Sync enabled. Please enable/disable in AD."
}else{
return "Set account enabled state to $AccountEnabled for $UserId"
}

} catch {
$ErrorMessage = Get-CippException -Exception $_
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not disable sign in for $UserId. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
return "Could not disable $UserId. Error: $($ErrorMessage.NormalizedError)"
}
}