powershell – PSCredentialUIOptions.Default和PSCredentialUIOptions.ValidateUserNameSyntax有什么区别?

Power
Shell中用于$Host.UI.PromptForCredential方法的重载之一有一个options参数,它是PSCredentialUIOptions值的按位组合.

MSDN for PSCredentialUIOptions我发现枚举值包括:

Default : Validates the user name, but not its existence or
correctness.

ValidateUserNameSyntax : Validates the syntax of the user name, but
not its existence or correctness.

这些描述到底意味着什么?

对于Default,当它验证用户名时,是否意味着它只是检查用户是否在PSCredentials对话框的User Name字段中输入了什么内容?

对于ValidateUserNameSyntax,它如何验证用户名的语法?通过检查输入文本中的非法字符?

我已经尝试使用谷歌搜索获取更多信息,但所有链接只返回MSDN页面或相同的TechNet页面.

最佳答案 ValidateUserNameSyntax不仅检查非法字符,还根据您提供给PromptForCredential()的allowedCredentialTypes验证用户名的格式:

$PromptCaption = "Creds plz!"
$PromptMessage = "Please input your domain credentials"

$CredentialType = [System.Management.Automation.PSCredentialTypes]::Domain
$ValidateOption = [System.Management.Automation.PSCredentialUIOptions]::ValidateUserNameSyntax

$Host.UI.PromptForCredential($PromptCaption,$PromptMessage,"","",$CredentialType,$ValidateOption)
点赞