MOL: Learn PowerShell Scripting (LiveBook) Ch15. Error

Welcome Forums General PowerShell Q&A MOL: Learn PowerShell Scripting (LiveBook) Ch15. Error

This topic contains 1 reply, has 2 voices, and was last updated by

6 months, 2 weeks ago.

  • Author
  • #113810

    Topics: 1
    Replies: 0
    Points: 1
    Rank: Member

    Noticed what appears to be an error in the MOL Livebook:

    If you copy and run this code as is, the Do Loop results in an infinite loop due to the placement of the variable $protocol. For example, if there is an error, the code will move to the Catch block change the $protocol variable, but then change right back to the original protocol. Further, it appears to me that this code on success will be stuck in an infinite loop as well, since the Do Loop has no way of completing the Until condition within the Try block.

    Ch15. Listing 15.2 "Our Take":


    One way to fix the infinite loops might be adjust the code as follows:

    Move the initial $protocol variable above the Do loop.

    Process {
         foreach ($Computer in $ComputerName) {
         $protocol = 'Wsman'
             Do {
               Try {

    and create exit condition in the Try block

    $session | Remove-CimSession
    #Exit condition of Do loop
    $protocol = 'Stop'
  • #113819

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Thank you – we'll try and get that information to the publisher.

The topic ‘MOL: Learn PowerShell Scripting (LiveBook) Ch15. Error’ is closed to new replies.

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