How to Change Outlook Password in 3 Different Ways

How to Change Outlook Password in 2 Easy Steps

Introduction Before you change your Outlook Password you have to first change it with your email provider. The reason...
spotify web player not working

Spotify Web Player Not Working [Fixed]

Introduction Spotify Web Player may stop working for you with the following error messages: "Spotify Web Player an Error...
DISM.exe /Online /Cleanup-Image /Restorehealth

DISM.exe /Online /Cleanup-Image /Restorehealth Explained

What is DISM.EXE /Online /Cleanup-image /RestoreHealth? "DISM.exe /Online /Cleanup-Image /Restorehealth" is a DISM command that repairs issue with the...
DHCP Relay agent

DHCP Relay Agent: Configuration in Windows Server 2016

What is a DHCP Relay Agent? A DHCP Relay Agent allows DHCP clients in a different network subnet to...

PowerShell ForEach: Syntax, Parameters, Examples

What is PowerShell ForEach? PowerShell ForEach (ForEach PowerShell) is a PowerShell construct used in iterating through values in a...


Remote Desktop Connection

Remote Desktop Connection an Internal Error Has Occurred [Fixed]

Introduction I recently received the error message "Remote Desktop Connection an Internal Error Has Occurred". It was strange because...

Find My Samsung: Register and Use Samsung Find my Mobile

Introduction Ever wondered how you could find your Samsung phone if you lost it? Find my Samsung or Samsung...
PowerShell vs CMD

Powershell vs CMD: Differences and Similarities Compared

Introduction This short guide compares PowerShell vs CMD (Windows command prompt). I will cover the history and nature of...
Spotify No Longer Supports this Version of Microsoft Edge

Spotify No Longer Supports this Version of Microsoft Edge [Fixed]

Introduction When you open Spotify web player on Microsoft Edge, you may receive the error message "Spotify No Longer...
Windows 10 Won't Boot

Windows 10 Won’t Boot With Black Screen? 3 Ways to Fix It

Why Won't Windows 10 Boot Up? If your Windows 10 stops with a black screen, the first question in...



RAID 50 vs RAID 10: Benefits and Disadvantages Compared

What is RAID 50 vs RAID 10? RAID 50 stripes two RAID 5 arrays while RAID 10 stripes two...
Check Disk (CHKDSK) Windows 10

Check Disk (CHKDSK) in Windows 10: Syntax, Parameters, Examples

Introduction Check Disk (CHKDSK) is a Windows 10 command tool that checks a disk for errors, fixes errors, recovers...
How to Check Windows 10 Version

How to Check Windows 10 Version in 4 Easy Ways

Introduction Wondering how you can check your version of Windows 10? Here are 4 easy ways for you -...
active directory interview questions

35 Active Directory Interview Questions and Answers

I have compiled 35 Active Directory interview questions and answers. Where necessary, I have also provided additional information to help you understand...
Amazon Merch

Amazon Merch: Your Definitive Guide to Merch by Amazon

What is Amazon Merch? Merch by Amazon (MbA or Amazon Merch) is a T-shirt Print-On-Demand platform that allows you...


how to merge cells in excel

How to Merge Cells in Excel in 2 Easy Ways

Introduction You can merge two Cells in Excel using CONCATENATE function or the “&” (ampersand) operator. Though Excel has...
How to Make a Pivot Table in Google Sheets

How to Make a Pivot Table in Google Sheets

Introduction You can make a Pivot Table in Google Sheets to simplify analysis of complex data. A Pivot Table...
how to make Pivot Table

How to Make a Pivot Table in Excel

Introduction A Pivot Table allows you to analyze, summarize and calculate large data to help find relationships. With a...
RAID 3 (Redundant Array of Independent Disks) Explained

RAID 3 (Redundant Array of Independent Disks) Explained

What is RAID 3? RAID 3 is a RAID implementation that uses striping with a dedicated parity disk....
RAID 5 vs RAID 6

RAID 5 vs RAID 6: Differences, Benefits and Disadvantages

What is RAID 5 vs RAID 6? RAID 5 and RAID 6 uses striping with distributed parity technique. However,...
concatenate excel

Concatenate in Excel: How to Concatenate Columns and Strings

What is Concatenate in Excel? Concatenate in Excel is joining two strings into one continuous string. You can join...

How to Add in Excel (Excel Sum) with Examples

Introduction There are different ways to add numbers in Excel. You could simply select the cells containing the data....
Excel Count

Excel Count: How to Count in Excel With Examples

Introduction Excel COUNT Function is used for counting items in a worksheet. Excel COUNT also has the conditional function,...
powershell.exe -command

Powershell.exe Command: Syntax, Parameters and Examples

Introduction You may be wondering why write on Powershell.exe Command. Are there special commands for Powershell.exe? Yes! When you...
how to move columns in excel

How to Move Columns to Rows and Rows to Columns in Excel

Introduction If you receive some Excel data in columns, you can easily move the columns to rows in Excel...


Get Help With File Explorer in Windows 10

Introduction Need to get help with the new file explorer in Windows 10? You are in the right place....
Absolute Reference vs Relative Reference Excel

Absolute Reference vs Relative Reference Excel: Quick Guide

What is Absolute Reference in Excel? Absolute reference in excel allows you to reference a particular row or column...
Windows Boot Manager (BOOTMGR)

Windows Boot Manager: Edit Bootmgr, Fix Boot Errors in Windows 10

What is Windows Boot Manager? Windows Boot Manager (Bootmgr.exe) is a component of the new Windows Boot Loading Architecture...
Walmart Baby Registry

Walmart Baby Registry: Your Definitive Guide

Introduction Walmart Baby Registry gives expectant mothers a place to create a list of items they need for their...
how to install windows 10

How to Install Windows 10: Step by Step with Pictures

What you need to Install Windows 10 To learn how to install Windows 10 you need the following:

Powershell For Loop Explained: Syntax and Examples



“Powershell For Loop” (or Statement) is a construct that is used to run a command in a block while a condition evaluates to True. The word “while” is essential here as “Powershell For Statement” is used to iterate an array of values and to operate on a subset of these values. The For Loop will continue to repeat as long as the condition is True.

The For Loop is different from PowerShell ForEach Statement. While For Loop iterates an array of values and operates on a subset of these values, ForEach Statement iterate all the values in an array. The key difference is in the words subset and all.

If it is still confusing, do not worry. This guide offers a simplified explanation of “Powershell For Loop”, including Syntax and applicable examples.


Powershell For Loop Syntax

The Syntax of “Powershell For Loop” is:

for (<init>; <condition>; <repeat>)
{<statement lists>}

Powershell For Loop Parameters

This section explains the parameters in the PowerShell For Loop Syntax.

Init – is used to set a starting variable for the For Loop. Typically, the Loop will evaluate this value first based on the condition in the condition block. The next time the For Statement runs, the value in the Init will be adjusted based on the Repeat block. Then the new value will be evaluated based on the condition. And so on. An example of Init value for a For Loop could be “$a = 1”, without the quotes.

Condition – is where a condition is placed to evaluate values from the Init block. PowerShell evaluates the value in the Condition block and determines whether it is $True or $False. If the condition is $True, the commands in the statement lists block will run. The PowerShell For Loop will continue to repeat until the condition becomes $False. Then PowerShell will exit.

Repeat – is used to add commands that are evaluated each time the loop repeats. Refer to the example I gave in the Init parameter explanation. If Init is “$a = 1”, the Repeat value could be $a++. This tells PowerShell to increment the value in the Init value by 1 each time the PowerShell For Loop repeats. So, the first time the For Statement runs, the Condition block will check with the value of 1. When it runs next, it will check with 2 (1+1) and so on. As I said earlier, the For Loop will continue until the condition evaluates to $False.

Statement list – is the actual command that is executed each time the PowerShell For Loop repeats. An example command could be “Write-Host $a”. This will simply display the value each time the Loop repeats.

Powershell For Loop Examples

The PowerShell For Loop has 2 main blocks. The first block is enclosed in (), the second in {}. Moreover, within the () block, there are 3 sub-blocks. Init, Condition and Repeat blocks. Finally, the {} block contains the command that runs each time the For Statement repeats.

With this in mind, this section will be used to share some examples of the PowerShell For Loop.

Powershell For Loop Example 1: Basic

My first example is very basic. I want to display the numbers 1, 2 and 3. To do this, I will set an Init value of 1 ($a = 1). Then add a condition to evaluate if the Init value is less than or equal to 3 ($a -le 3).

Next, I will add a value of $a++ in the Repeat block. This will increment the Init value of the Init value, $a by 1 each time the Loop repeats. Finally, I will add a code in the Statement list block (Write-Host $a). This will display the values of a$ on the screen.

Here is the code

For($a=1; $a -le 3; $a++) {Write-Host $a}

and the result…

Powershell For Loop Example 1: Basic

Powershell For Loop Example 2: Multiple Operations

The Init, Condition and Repeat blocks of the PowerShell For Lop can take multiple operators. The following examples illustrate how to use multiple operators in the Powershell For Loop.

The original Syntax of the For Loop is:

 for (<init>; <condition>; <repeat>)
{<statement lists>}

In my previous example, I gave this basic example:

 For($a=1; $a -le 3; $a++) {Write-Host $a} 
If you look closely you will notice that the Init, Condition and Repeat blocks are separated by a semicolon, ;.

To add multiple Init operators, we enclose each in a () and separate them with a coma ,. If you add multiple Init operators, you will then need to have multiple Condition and Repeat operators.

Multiple Condition include Logical Operators for additional comparison of 2 conditions. Click about_Logical_Operators to read about them.

Here is an example of how to use multiple operators in a PowerShell For Loop:

for( ($a=1),($b=1); $a -le 3 -and $b -le 5; $a++,$b++) 
Write-Host $a
Write-Host $b
To run this script open PowerShell ISE. Then copy the code and paste the code in PowerShell ISE. Finally, click Run Script.

Here is the result of the previous script

 Powershell For Loop Example 2: Multiple Operations

Notice that the output for both $a and $b variables went up to a maximum of 3 even though $b has the condition $b -le 5. The reason is the -and logical operator.

Here is why:

Each time the Loop repeats, the -and operator checks whether the values returned by $a -le 3 AND $b -le 5 are the same. It is only when they are the same that the Loop will execute the command in the {} block.

So, even though $b -le 5 could have resulted in 4 and 5, during the Loop, the values will NOT be used for execution because they will not be the same value as $a -le 3, which produces a maximum of 3 – less than or equal to 3.


“Powershell For Loop” (or Statement) construct is useful for building scripts for automating Windows tasks. I hope this guide simplified it enough.

If you have any question or comment, use the “Leave a Reply” form at the end of the page. Alternatively, you could share your experience using PowerShell For Loops.

Other Helpful Guides

Additional Resources and References



Please enter your comment!
Please enter your name here

By using this website you agree to accept our Privacy Policy and Terms & Conditions