Скрипт PowerShell работает нормально, если я запускаю его построчно, но при попытке запустить скрипт как один, поиск пользователей не приходит вовремя для следующего вопроса. Пожалуйста, дайте мне знать, как я могу заставить третью строку сценария появиться в соответствии с запросом вместо этого.
$name = Read-Host "What is the user's first name or letter?"
$list = Get-ADUser -Filter * | ? {$_.SamAccountName -match $name} | select SamAccountName | sort SamAccountName
$list
$DisableUser = Read-Host "Copy and paste the user here"
$t = $DisableUser
$year = Read-Host "Please input the year the user should be disabled, in this format (YYYY)"
$month = Read-Host "Please input the month the user should be disabled, in this format (MM)"
$day = Read-Host "Please input the day the user should be disabled, in this format (DD)"
$date = "$month/$day/$year"
$hour = Read-Host "Please input the hour of the day the user should be disabled, in this format (HH)"
$minute = Read-Host "Please input the minute the user should be disabled, in this format (MM)"
$seconds = Read-Host "Please input the second the user should be disabled, in this format (SS)"
$ampm = Read-Host "AM or PM?"
$Time = "${hour}:${minute}:${seconds} ${ampm}"
$dandt = "$date $Time"
$dandt
Write-host "$t will be disabled on this date, $dandt"
$answer = Read-Host "Is this correct? Please type Yes or No"
$l = $answer
If ($l -like "y*")
{Set-ADAccountExpiration $t -DateTime $dandt}
ELSE { "Exiting"; Return}