I basically created a custom schema with a few bool values, "2SV_Exempt", "Notif_Exempt", "First_2SV_Email", "Second_2SV_Email","Final_2SV_Email".
Not sure what OS you're running, but I am doing mine via Windows with PowerShell... Here's the command I ran to create the schema and fields:
I then run a job that checks for users in our New Hire OU, fills all of the custom schema fields as False if they for users new enough that they haven't had the job run against them yet, then cycles through each user and checks for notifications sent. If they have received the first notification and are still not enrolled in 2SV, they are sent a second notification and the second notification custom schema value is marked as "True", etc....
Here's the full user loop that I run... This handles schema updating, email sending, enrolled user moving to 2SV enforced OU, and suspension if they have received 3 notifications and are still not enrolled... Also includes logging and some other variables that are set outside this snippet:
foreach ($user in $allusers | ? {$_.'customSchemas.2SV.2SV_Exempt' -eq "False" -and $_.'customSchemas.2SV.Notif_Exempt' -eq "False" -and $_.lastLoginTime -ne "Never" -and $_.suspended -eq "False"})
{
"" | Add-Content $txtlog -PassThru
$UserEmail = $user.primaryEmail
$UserFullName = $user.'name.fullName'
$2svEnrolled = & $GAM report users user $UserEmail fields 'accounts:is_2sv_enrolled' | ConvertFrom-Csv | select -ExpandProperty 'accounts:is_2sv_enrolled'
if ($2svEnrolled -eq "False")
{
$FirstNotif = $user.'customSchemas.2SV.First_2SV_Email'
$SecondNotif = $user.'customSchemas.2SV.Second_2SV_Email'
$FinalNotif = $user.'customSchemas.2SV.Final_2SV_Email'
"$UserEmail is not currently enrolled in 2-Step Verification - Checking if user has received any notification emails" | Add-Content $txtlog -PassThru
if ($FirstNotif -eq "False" -and $SecondNotif -eq "False" -and $FinalNotif -eq "False")
{
"$UserEmail has not yet received a 2SV notification email - sending first email" | Add-Content $txtlog -PassThru
& $GAM update user $UserEmail 2SV.First_2SV_Email True
& $MailScript -UserEmail $UserEmail -UserName $UserFullName -Notification "first"
}
elseif ($FirstNotif -eq "True" -and $SecondNotif -eq "False" -and $FinalNotif -eq "False")
{
"$UserEmail has only received the first 2SV Email - sending second email" | Add-Content $txtlog -PassThru
& $GAM update user $UserEmail 2SV.Second_2SV_Email True
& $MailScript -UserEmail $UserEmail -UserName $UserFullName -Notification "second"
}
elseif ($FirstNotif -eq "True" -and $SecondNotif -eq "True" -and $FinalNotif -eq "False")
{
"$UserEmail has received 2 2SV Emails - sending final email" | Add-Content $txtlog -PassThru
& $GAM update user $UserEmail 2SV.Final_2SV_Email True
& $MailScript -UserEmail $UserEmail -UserName $UserFullName -Notification "final"
}
elseif ($FirstNotif -eq "True" -and $SecondNotif -eq "True" -and $FinalNotif -eq "True")
{
"$UserEmail is not enrolled in 2SV or exempt and has received the final email - suspending user due to non-compliance" | Add-Content $txtlog -PassThru
& $GAM update user $UserEmail Suspended True 2SV.Notif_Exempt True
& $MailScript -UserEmail $UserEmail -UserName $UserFullName -Notification "suspended"
}
sleep 2
& $GAM print users query "email:$UserEmail" fullname ou creationtime lastlogintime custom all suspended | ConvertFrom-Csv
}
elseif ($2svEnrolled -eq "True")
{
"$UserEmail has enrolled in 2-Step Verification -- moving user to 2-Step Enforced OU" | Add-Content $txtlog -PassThru
& $GAM update user $UserEmail org "/Users/New Hire Staging/2-Step Enforced"
sleep 2
& $GAM print users query "email:$UserEmail" fullname ou creationtime lastlogintime custom all suspended | ConvertFrom-Csv
}
else
{
"Reports are not yet generated for $UserEmail, unable to determine 2-Step Enrollment status -- moving to next user." | Add-Content $txtlog -PassThru
}
}