Why only some part of ScriptBlock is being executed

Welcome Forums General PowerShell Q&A Why only some part of ScriptBlock is being executed

This topic contains 5 replies, has 3 voices, and was last updated by

GS
 
Participant
3 years, 3 months ago.

  • Author
    Posts
  • #34387
    GS

    Participant
    Topics: 108
    Replies: 186
    Points: 12
    Rank: Member

    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

    Participant
    Topics: 4
    Replies: 262
    Points: 60
    Rank: Member

    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
    GS

    Participant
    Topics: 108
    Replies: 186
    Points: 12
    Rank: Member

    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
    GS

    Participant
    Topics: 108
    Replies: 186
    Points: 12
    Rank: Member

    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

    Participant
    Topics: 2
    Replies: 376
    Points: 0
    Rank: Member

    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
    GS

    Participant
    Topics: 108
    Replies: 186
    Points: 12
    Rank: Member

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

The topic ‘Why only some part of ScriptBlock is being executed’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort