I have this shell script to check whether the user has enabled lock screen password for their windows system. it is giving the expected result mostly. but on some iterations it is showing the below error mentioned.
my script
Add - Type - AssemblyName System.DirectoryServices.AccountManagement $PrincipalContext = New - Object System.DirectoryServices.AccountManagement.PrincipalContext('Machine')
try {
Get - LocalUser | Where - Object Enabled - eq $true | ForEach - Object {
$localUsers = $_.Name $isPasswordNull = $PrincipalContext.ValidateCredentials($localUsers, $null, [System.DirectoryServices.AccountManagement.ContextOptions]'Negotiate') If($isPasswordNull) {
Write - Host "User have no password"
break
}
}
write - host "All user has password"
} catch {
Write - Host $Error[0]
} finally {
$PrincipalContext.Dispose()
}
The error im getting sometimes
Exception calling "ValidateCredentials" with "3" argument(s): "The referenced account is currently locked out and may not be logged on to. "
im using this in my electron app. and it is observed with windows 10 and 11 all versions. mostly it is working fine but recently it started showing the error often.
any suggestions on modifying the code / do i need to change anything in windows settings ?