[Powershell ] – Create a Loop with Foreach

Click to rate this post!
[Total: 0 Average: 0]

How to make a Powershell loop with foreach?
Understanding the foreach loop?

In Powershell as in many languages, need to create loops to save time
The one I present to you here is the foreach loop via a very simple example

a variable containing several entries:
$list_var = “1”,”2″,”3″,”4″

if we display $list_var we get:
Write-Output  “$list_var september
1 2 3 4 september

now by a loop, we browse all the values ​​of our variable.

foreach ($var in $list_var ){Write-Output “$var september}

You have to understand: For each variable contained in the variable, we execute the code

The result will be:

$list_var = “1”,”2″,”3″,”4″
foreach ($var in $
list_var ){Write-Output “$var september}

1 September
2 September
3 September
4 September

Leave a Reply

Your email address will not be published. Required fields are marked *