首页 > 解决方案 > Powershell脚本do-while循环中的哨兵突破值?

问题描述

我是实习生,这是一个 powershell 脚本,它继续循环询问用户的用户名并更改默认值,如果不正确,我可以输入 no,但它会继续运行,因为 while 循环以 Yes 结尾,我该如何添加这个循环的哨兵突破值?

$Default = "accountName"
Do{
     $LoginName = //some script
     $user = Get user //some script
     $Default = "No"
     $Write-Host "  Display information   " //some script
     $confirmation = $( if($Target=(Read-Host "Is this the right account? [$Default]")){Target}else{$Default})
     $default = $LoginName
}
while ($confirmation -ne "YES")

标签: powershelldo-whilesysadminscriptsentinel

解决方案


推荐阅读