This powershell command will involve the for loop. This type of loop iterates through a sort of timer, when that condition is met the loop stops.
For example in C a for loop looks like this. $a variable is initials set to 1. Our condition is set to $a less than 5. The last part it the iteration value it’s updated during the loop. Finally the value of a is printed.
for ( int a = 1; a <= 5 ; a++ )
{
printf(“%d\n”,a);
}
1
2
3
4
5
In powershell the > and < are part of the operators used for command redirection. So we will have to instead use operators such as -lt less than.
For example our for loop will look like this below to create 5 folders.
for($a=0;$a -lt 5;$a++){powershell command}
To create a folder the new-item cmdlet will be used. Basics are use -type to specify file or document. We will specify document. Finally choose a name using -name option.
Below a for loop is used to create 12 folders name Week 1..12
for ($a=1;$a -le 12;$a++)
{
New-Item -type Directory -Name (“Week “+$a)
}
By the way the () in the name means that the first thing that will happen is Week will be combined with $a value. Then the full new-item cmdlet runs.