2017-11-17 11 views
0

コードの最後にキャリッジリターンを書き込むまで、コードはGet-ADUserコマンドの結果を返しません。Write-HostおよびRead-Hostの後までPowerShellコマンドの出力が表示されない

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結果は出力パイプラインにあります。

通常、これにより、値を別のスクリプトに戻すことができます(たとえば、後で処理するため)。それを割り当てたり出力をキャプチャしたりしないので、デフォルトのフォーマッタに行き、実行が終了する前に他のものの後に表示されます。

本当に出力を表示したい場合は、Get-ADUserコールの最後に| Write-Hostを追加することができます。これを別のスクリプトに接続したい場合は、値を変数に取り込み、次にWrite-HostWrite-Outputの両方をパイプラインに追加することができます。

参照:[選択] - オブジェクトの後に一時停止することができませんまたはスリープ]のUnderstanding the Windows PowerShell Pipeline

関連する問題