不显示结果,直到写主机和读主机
问题描述:
代码将不会返回获取-ADUser便有命令的结果,直到后,我打的代码结束后回车不显示结果,直到写主机和读主机
Write-Host "Please enter the user account name. Ex. jsmith1" -ForegroundColor Yellow -BackgroundColor Black
$Username = Read-Host
"`n"
Write-Host "Is this the correct username? $Username" -ForegroundColor Yellow -BackgroundColor Black
Write-Host "If Yes Type 1; If No type 2" -ForegroundColor Yellow -BackgroundColor Black
$Continue1 = Read-Host
IF ($Continue1 -eq 1)
{
Get-ADUser -Server "contoso.com" -filter * -Properties * | Where {$_.SamAccountName -match $Username} | Select DisplayName, SamAccountName, EmployeeID, EmployeeNumber
}
ELSE
{}
Write-Host "Would you like to update the Employee ID and the Employee Number?" -ForegroundColor Yellow -BackgroundColor Black
Write-Host "If Yes Type 1; If No type 2" -ForegroundColor Yellow -BackgroundColor Black
$Continue2 = Read-Host
缺少什么我在这里?
答
的Write-Host
项目的命令的执行过程中立即显示出来。
的Get-ADUser
结果是在输出管道。
正常情况下,您可以将该值返回到另一个脚本中,例如,用于进一步处理。由于您不分配或捕获输出,因此它只会转到默认格式化程序,并在执行结束之前显示在其他所有内容之后。
如果您确实想要显示输出结果,您可以将| Write-Host
添加到Get-ADUser
调用的结尾处。如果您想将其连接到另一个脚本,可以将该值捕获到一个变量,然后Write-Host
,然后Write-Output
将其添加回管道。
的可能的复制[无法暂停或睡眠后选择-对象(https://stackoverflow.com/questions/34835327/unable-to-pause-or-sleep-after-选择对象) – PetSerAl