here's my Code, the output should show up every 5 seconds but now i can't see anything when the script is running, after code in while{},the output will show up at the same time, you can see the picture attached
but when i change this $ShowStatus|ft -AutoSize to write-host $showstatus i can see the output in this format every 5 seconds @{ResourceGroup=mxytest; VMName=AD-BJ; OS=Windows; static=Running; Time=2017/5/31 17:33:27}
if ($VMJobIDs -ne $null)
{
$NotCompleted = $true
while ($NotCompleted)
{
$NotCompleted = $false
[pscustomobject[]]$ShowStatus = $null
foreach ($VMJobID in $VMJobIDs)
{
#Write-Host "$(Get-Date)" -ForegroundColor Yellow
$VMJob = Get-Job -Id $VMJobID
if ($VMJob.State -eq "Completed")
{
if ($VMJob.HasMoreData)
{
$FinalResult = $null
$FinalResult = New-Object -TypeName psobject
$Result = Receive-Job -Id $VMJob.id
$FinalResult | Add-Member -MemberType NoteProperty -Name ResourceGroup -Value $ResourceGroupName
$FinalResult | Add-Member -MemberType NoteProperty -Name VMName -Value $($VMJob.Name)
$FinalResult | Add-Member -MemberType NoteProperty -Name OS -Value $VMOSInfo.($VMJob.Name)
$FinalResult | Add-Member -MemberType NoteProperty -Name Succeed -Value $($Result.IsSuccessStatusCode)
$FinalResult | Add-Member -MemberType NoteProperty -Name Time -Value $(Get-Date)
$FinalResults += $FinalResult
}
}
else
{
$NotCompleted = $true
}
$Show = $null
$Show = New-Object -TypeName psobject
$Show | Add-Member -MemberType NoteProperty -Name ResourceGroup -Value $ResourceGroupName
$Show | Add-Member -MemberType NoteProperty -Name VMName -Value $($VMJob.Name)
$Show | Add-Member -MemberType NoteProperty -Name OS -Value $($VM.StorageProfile.OsDisk.OsType.Tostring())
$Show | Add-Member -MemberType NoteProperty -Name static -Value $($VMJob.State)
$Show | Add-Member -MemberType NoteProperty -Name Time -Value $(Get-Date)
$ShowStatus += $Show
}
#Write-Host ("$(Get-Date) * Trying to install the extension...Please wait") -ForegroundColor Yellow
$ShowStatus|ft -AutoSize
#Write-Host ("$(Get-Date) * Trying to install the extension...Please wait") -ForegroundColor Yellow
Start-Sleep 5
}
}
if ($FinalResults -ne $null)
{
return $FinalResults
}