我有一个powershell脚本,我希望用户输入一个值,脚本返回一个随机字符串作为密码.如果他们只是在提示输入密码长度时按Enter键,我希望它是9个字符的默认值.
我怎么处理没有输入?
我试过这样的事情,但不认为这是对的:
Write-Host输入密码长度要求:
$length = Read-Host
IF ( $length -eq $NULL)
{ Do continue on with the value of 9 for the length}
ELSE
{Use $length for the rest of the script}
Run Code Online (Sandbox Code Playgroud)
其他部分工作得很好; 然而,当生成密码时,我一直发现自己一遍又一遍地输入9.我宁愿直接进入.
任何帮助是极大的赞赏!
powershell ×1