Why only some part of ScriptBlock is being executed

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of GS GS 8 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #34387
    Profile photo of GS
    GS
    Participant

    I'm completely at loss why following code produces only output 1 and never 2. It works locally on my desktop but fails on every remote computer I tried.

    PS C:\Windows\system32> Invoke-Command -ComputerName computer1 -ScriptBlock {Write-Output 1; Write-Output 2} 
    1
    
    
    #34388
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Hi GS,

    It works okay for myself, both locally and remotely?

    PS C:\> Invoke-Command -ComputerName tapvnxdev01 -ScriptBlock {Write-Output 1; Write-Output 2}
    1
    2
    PS C:\>
    
    #34390
    Profile photo of GS
    GS
    Participant

    This seems to be not working on PS 2.0 and works on PS 4.0. Every Windows 2008 box I tried failed but Windows 2012 worked.

    #34396
    Profile photo of GS
    GS
    Participant

    This seemed to be yet another bug in PS 5.0.
    I can reproduce at will this bug to any number of servers.
    Invoke-Command executes only first line of ScriptBlock when sourced from PS 5.0 to PS 2.0

    
    PS C:\Windows\system32> invoke-command win2008 {write-output 1; write-output 2}
    1
    PS C:\Windows\system32> invoke-command win2012 {write-output 1; write-output 2}
    1
    2
    PS C:\Windows\system32>
    
    #34417
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    Can confirm this. Strange addition:

    if { write-output 1; write-output 2; write-output 3; } – get only 1
    if I use scriptblock as { 1;2;3 } it output 1,2,3;
    if { write-output 1; write-output 2; 3l } – get 1,2,3

    thus bug exists with write-output, but plain out works and even push previous write-output

    #34420
    Profile photo of GS
    GS
    Participant

    WMF 5.0 is more buggy then WIndows NT SP 6 and that was the all time low for Microsoft.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.