Using a series of numbers to loop through an object or process.

I wanted to share this to help people that have to build scripts that parse/writes tons of files. I always use the numbers depending on scale like the following. 1..17 | |foreach-object {Write-Output “User$_”} another example if you need files: $objectarray=@() 1..17 | |foreach-object {new-object psobject  -property @{ name=”User$_”} Well depending on the task you…

I wanted to share this to help people that have to build scripts that parse/writes tons of files.

I always use the numbers depending on scale like the following.

1..17 | |foreach-object {Write-Output "User$_"}

another example if you need files:

$objectarray=@()

1..17 | |foreach-object {new-object psobject  -property @{ name="User$_"}


Well depending on the task you can create a dev variable of sorts. to contain your creation of variables is sound and effective.

I wouldn’t rely on it in a production script unless you did a “foreach($this in $that)” scenario.

chime in if you have any questions or request. I welcome a challenge.

More from the blog