Calling Web Services in Password Reset Server with PowerShell

 Here is an example of using PowerShell script calls Authenticate, UserEnrolled and ImportAnswers. Note that the you will need PowerShell 2.0 (and not the default 1.0) installed to run the script. Replace the relevant parameters with your own values:


Authenticate:
$domain = 'MyDomain'
$username = 'admin'
$password = 'password'
$url = 'http://www.MyPasswordResetServer.com/webservices/webservice.asmx'
$proxy = New-WebServiceProxy -uri $url -UseDefaultCredential 
$token = $proxy.Authenticate($domain, $username, $password).Token

UserEnrolled:
$url = 'http://www.MyPasswordResetServer.com/webservices/webservice.asmx'
$proxy = New-WebServiceProxy -uri $url -UseDefaultCredential 
$token = $proxy.Authenticate($domain, $username, $password).Token
$enrolled=$proxy.UserEnrolled($env:USERDOMAIN,$env:USERNAME) 


Here we used the variables $env:USERDOMAIN and $env:USERNAME to retrive the current domain and username of the user currently logged into the machine. These can be replaced with hard coded or using a loop to check multiple users enrollment status.

Import Answer:
$domain = 'MyDomain'
$username = 'admin'
$password = 'password' 
$questionName='Favorite Animal' 
$answer ='cat' 
$countryCode='' 
$extension=''
$url = 'http://www.MyPasswordResetServer.com/webservices/webservice.asmx'
$proxy = New-WebServiceProxy -uri $url -UseDefaultCredential 
$token = $proxy.Authenticate($domain, $username, $password).Token
$importAnswer = $proxy.ImportAnswer($token,$domain,$username,$questionName,$answer,$countryCode,$extension)


*$countryCode and $extensioncan be left as empty strings when not blank when not importing an answer for phone or SMS questions.

Article ID: 382, Created On: 11/27/2013, Modified: 11/27/2013

Feedback (0)