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 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.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Profiting by gaining everything!

    What does “having it all” mean to you? Is it attainable? What does it mean to have it all? To me, it means that we’re thinking about the projects that…

    ·

  • Leader in Following

    Are you a leader or a follower? I want you to read into this without reading too deeply. I believe good leaders are followers. So for most things in this…

    ·

  • Faded memories and logos

    What’s the oldest things you’re wearing today? So the oldest thing that I’m wearing today is actually my Samsung jacket, and it reminds me a lot of where I’ve come…

    ·

Spam-free subscription, we guarantee. This is just a friendly ping when new content is out.

Go back

Your message has been sent

Warning
Warning
Warning.