# convert SecureString to a plain text # (the system method requires clear-text) $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# test password $PrincipalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($context, $Domain) $PrincipalContext.ValidateCredentials($UserName,$plain) }