Вы должны использовать трубу для оператора или, чтобы работать не как косая черта
Этот ...
while ($choice -notmatch "y/n"
... должно быть это ...
while ($choice -notmatch "y|n"
Это неправильно, потому что в опубликованном коде нет заполненной переменной для использования ...
Disable-ADAccount $Username
... исходя из вашего кода, должно быть это ...
Disable-ADAccount $User
Нет необходимости разделять переменную в выборе выбора. Просто сделай это.
$choice = read-host "Are you sure you want to disable the following user? (Y or N) $name"
Пример:
$choice = ""
$User = read-host "enter username"
$Name = $User
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")
{ $User }
}
enter username: test
Are you sure you want to disable the following user? (Y/N) test: u
Are you sure you want to disable the following user? (Y/N) test: u
Are you sure you want to disable the following user? (Y/N) test: y
test
enter username: test1
Are you sure you want to disable the following user? (Y/N) test1: h
Are you sure you want to disable the following user? (Y/N) test1: h
Are you sure you want to disable the following user? (Y/N) test1: n