2017-11-17 220 views
0

代碼將不會返回獲取-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 

缺少什麼我在這裏?

+0

的可能的複製[無法暫停或睡眠後選擇-對象(https://stackoverflow.com/questions/34835327/unable-to-pause-or-sleep-after-選擇對象) – PetSerAl

回答

0

Write-Host項目的命令的執行過程中立即顯示出來。

Get-ADUser結果是在輸出管道。

正常情況下,您可以將該值返回到另一個腳本中,例如,用於進一步處理。由於您不分配或捕獲輸出,因此它只會轉到默認格式化程序,並在執行結束之前顯示在其他所有內容之後。

如果您確實想要顯示輸出結果,您可以將| Write-Host添加到Get-ADUser調用的結尾處。如果您想將其連接到另一個腳本,可以將該值捕獲到一個變量,然後Write-Host,然後Write-Output將其添加回管道。

參見:Understanding the Windows PowerShell Pipeline