Variable sampling with numbers.

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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