I am attempting to write a powershell script that will enroll users in the self-service password system. However I would like to execute the new enrollment only if the user is not currently enrolled.
This example gets me part of the way..
http://www.adaxes.com/tutorials_SelfSer ... dReset.htm
Import-Module Adaxes
$question1 = "What are the last 4 digits of your credit card?"
$question2 = "What is your social security number?"
foreach ($line in (Import-Csv c:\qa.csv))
{
$answer1 = $line.CardDigits
$answer2 = $line.SSN
# I would love an if statement here checking if user is already enrolled.
New-AdmPasswordSelfServiceEnrollment $line.User -QuestionsAndAnswers @{$question1=$answer1;$question2=$answer2} -AdaxesService localhost
}
Reviewing the SDK points at an adsi method within IAdmPasswordSelfServiceReportRecord called GetUserInfo that appears to have the information I require. I am not sure how to use this in PowerShell, there are no examples within that section of the SKD
# ... a bunch of code up above that queries a SQL database and returns $results and sets variables
foreach ($result in $results) {
$userObj = get-ADUser $result.Identity -Properties CanonicalName,sAMAccountName,distinguishedName
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly($AdaxesService)
$admUser = $admService.OpenObject(("Adaxes://" + $userObj.DistinguishedName), $NULL, $NULL, 0)
# i dont quite know what to put here...
if ( $admUser... ? -eq $false ) {
New-AdmPasswordSelfServiceEnrollment -Identity $result.Identity -QuestionsAndAnswers @{$question1=$pin;$question2=$result.DateOfBirth} -AdaxesService $AdaxesService
}
}
oh, and if New-admPasswordSelfServiceEnrollment command only "does anything" if there is no enrollment that would be great, but the system keeps re-enrolling every time I send the command.
I would love some assistance, thank you