在我在代码末尾点击回车之前,代码不会返回Get-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
,将它添加回管道。