When I execute this script in Sitecore Powershell ISE:
Write-Host 'This is a test'
$count = 0
$customObj = [PsCustomObject]@{
Ask = 'Hello'
Jeeves = 'World'
Count = $count
}
$customObj
while ($count -lt 10) {
Start-Sleep -seconds 1
$count++
$customObj.Count = $count
$customObj
}
It produces the following output, and each line appears in turn as the script progresses.
This is a test
Ask Jeeves Count
--- ------ -----
Hello World 0
Hello World 1
Hello World 2
Hello World 3
Hello World 4
Hello World 5
Hello World 6
Hello World 7
Hello World 8
Hello World 9
Hello World 10
If I try the same via a remote script call:
PS C:\Windows\System32> $session = New-ScriptSession ...
PS C:\Windows\System32> Invoke-RemoteScript -Session $session -ScriptBlock {
>> Write-Host 'This is a test'
>>
>> $count = 0
>> $customObj = [PsCustomObject]@{
>> Ask = 'Hello'
>> Jeeves = 'World'
>> Count = $count
>> }
>>
>> $customObj
>>
>> while ($count -lt 10) {
>> Start-Sleep -seconds 1
>> $count++
>> $customObj.Count = $count
>> $customObj
>> }
>> }
The output comes all at once at the very end, and the count is always 10. Additionally the Write-Host line is not captured. What's going on here?
Ask Jeeves Count
--- ------ -----
Hello World 10
Hello World 10
Hello World 10
Hello World 10
Hello World 10
Hello World 10
Hello World 10
Hello World 10
Hello World 10
Hello World 10
Hello World 10
