Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Service Accounts to fetch Last Password date from AD to ServiceNow

MJaveed
Tera Contributor

Hi All,

 

We have a requirement where we have "Last password date field" showing as "Empty" for few records in service Now . So, to fill in those we are asked to fetch the 'Last Password date" field from AD to ServiceNow. we have implemented a PowerShell script to fetch the data from not sure if the code written is right as I am completely new  to PS.

 

Also, not sure how we can test and run the script as we do not have any test mid server available.

 

Posting the code . please help if any errors and suggestions on any.

 

$domain = $domain -replace "%27","'";
$username = $username -replace "%27","'";

#Write-Host "Variable collection"

#Write-Host "CyberArk Vault script"
$credential = D:\service_account_script\get_password_cyberark.ps1 $domain
#Write-Host "Competed CyberArk Vault script"
#$server = Get-ADDomainController -Discover -Domain $domain
if($credential -ne $null)
{
$server = D:\service_account_script\get_AD_DC_details.ps1 $domain $credential
try{

Get-ADUser -identity $uspicorp.com -properties PwdLastSet | sort Name | ft Name,@{Name='PwdLastSet';Expression={[DateTime]::FromFileTime($_.PwdLastSet)}}


Write-Host "Last password has been changed"
}
catch{
Write-Host $_.Exception.Message
}
}
else{
Write-host "CyberArk Password Issue"

0 REPLIES 0