小编Mik*_*ike的帖子

Powershell while循环

下面的代码在到达时会一直陷入循环

$choice = read-host "Are you sure you want to disable the following user? (Y/N)" "$name"
Run Code Online (Sandbox Code Playgroud)

我键入y并继续循环该问题.

我尝试了一段时间和单一的IF语句.关于如何阻止这个循环的任何想法?

$choice = ""
$User = read-host "enter username"
$Name = Get-ADuser -Identity $Username | Select-Object Name

while ($choice -notmatch "y/n"){
    $choice = read-host "Are you sure you want to disable the following user? (Y/N)" "$name"

    If ($Choice -eq"Y"){
        Disable-ADAccount $Username
    } 
}
Run Code Online (Sandbox Code Playgroud)

powershell if-statement while-loop

0
推荐指数
1
解决办法
378
查看次数

标签 统计

if-statement ×1

powershell ×1

while-loop ×1