The iteration wizard (loop)

You can start the wizard from the BlueParq Designer or the BlueParq Editor.

BlueParq Designer

  1. Press the right mouse button, the BlueParq Radial Menu will present itself.

  1. Press the Add cmdlet call button

Trick: CTRL-2

Press the CTRL and 2 key simultaneously to call the wizard directly

BlueParq Editor

  1. In the Bottom Navigation bar of the BlueParq Editor, click the Show cmdlet wizard button

Trick: CTRL-2

Press the CTRL and 2 key simultaneously to call the wizard directly

The iteration wizard

  1. After opening the wizard the following screen will be displayed:

Add infinite loop protection

Add infinite loop protection in case you don't want to wait a long time...

  1. As you can see in the above screen you have a couple options to create your iteration:
    1. Counter: loop a number of times and perform an action at the specified increment.
    2. Iterate over a collection: this can be:
      1. A file or the content of a file.
      2. A typed list.
      3. An XML file.
      4. A CSV file, with a delimiter.
      5. A Hashtable, with Keys and Values.
      6. Generate your own, with a prefix, start value, increment, end value and post fix.
    3. Condition: loop as long as the specified condition is or isn't fulfilled.
    4. Timer: loop for a specified period of time.

Comments are great for documenting your PowerShell scripts!

The comments you create on several places will automatically be added to your annotations.

Counter

  1. Choose the Counter radio button.
  2. You can add a start value, end value and increment value. In this example the iteration will loop from 0 to 10, one step at a time.
  3. Click Finish and the block or PowerShell code will be created.

Iterate over a collection

  1. Choose the Iterate over a collection radio button.
  2. You can choose to iterate between the following collection methods:
    1. A file or the content of a file.
    2. A typed list.
    3. An XML file.
    4. A CSV file, with a delimiter.
    5. A Hashtable, with Keys and Values.
    6. Generate your own, with a prefix, start value, increment, end value, and postfix.

  1. In this example we will use the List collection and will add Hello world as with each letter on a single line.

  1. Click Finish and the block or PowerShell code will be created.

Condition

  1. In order to work with the Condition option, you first have to create a variable assignment.
  2. The fastest way is to click on the sign of the Variables node.
  3. Create a Boolean, just like the example below.
  4. In the BlueParq Editor you can add the following line of PowerShell code: [Bool] $LoopingAllTheWay = $true

  1. Press Save and then open the iteration wizard.
  2. Choose the Condition radio button.

  1. Now you can add logic to your condition, for example wait until a service is stopped or a process is started.
  2. Click Finish and the block or PowerShell code will be created.

Wise choice

In the above example it's a very wise choice to check the Add infinite loop protection checkbox.

Timer

  1. Choose the Timer radio button.
  2. You can add the total run loop time value and a perform action interval in this screen. In this example the iteration will loop 60 seconds, and will perform an action every 10 seconds.
  3. Click Finish and the block or PowerShell code will be created.

Result in the BlueParq Designer

We will use our Hello world example in the Iterate over a collection option.

  1. If we generate the diagram we will get the following result:

  1. Nice! But not very spectacular. As the loop will iterate each letter in the Hello world lines, but it will do that and nothing more.
  2. Let's just show the output of each letter. First of all right mouse click on the Group Element, the BlueParq Radial Menu will appear.
  3. Press the cmdlet wizard and press Echo in the search field. Also, check out the cmdlet wizard tutorial here.
  4. Press Echo under Alias and press Next.
  5. Make sure you add $item in the InputObject text box.

  1. Press Finish and the cmdlet block will be added within the Group Element.

Result in the BlueParq Editor

We will use our Hello world example in the Iterate over a collection option.
  1. If we generate the diagram we will get the following result:
ForEach ($item In ('H','e','l','l','o','','w','o','r','l','d'))
{
}
  1. Nice! But not very spectacular. As the loop will iterate each letter in the Hello world lines, but it will do that and nothing more.
  2. Let's just show the output of each letter.
  3. Press the cmdlet wizard from the Bottom Navigation bar and press Echo in the search field. Also checkout the cmdlet wizard tutorial here.
  4. Press Echo under Alias and press Next.
  5. Make sure you add $item in the InputObject text box.

  1. Press Finish and the cmdlet block will be added within the ForEach iteration.
ForEach ($item In ('H','e','l','l','o',' ','w','o','r','l','d'))
{
 Microsoft.PowerShell.Utility\Write-Output -InputObject $item
}

Result in PowerShell

Was this article helpful?
0 out of 0 found this helpful