1

I have a series of 29 powershell scripts that execute sequentially. All of the information in each script is the same, but I have a string $buildID that needs to change between each version. Is it possible to do the following:

  1. Import the $buildID variable from the previous script
  2. Increment said variable by 1 (either numerically or alphabetically)

If $buildID was an int it would be easy. I tried to figure out #2 first so I attempted solving it using the below method:

$buildID=[int[]][char[]]'TestA'
$i = 0

$buildID[-1]++
[char[]]$buildID -join ""
$i++

echo $buildID

This technically works, $buildID will show "TestB" afterwards, but whenever I try to use the variable it shows the value is actually "88". Additionally, since I need more than 26 iterations the alphabet rolls over into special characters (which the system wouldn't accept) and numbers would roll over as well after 9.

Can someone either fix my method or show me an even better one?

1
  • Why not simply use int and only pass this value on if the text part is fixed anyway and only the version part changes? Commented Jul 23, 2020 at 21:05

1 Answer 1

1

Just to give you an idea how this could work using an int which is way more suitable for incrementing:

$i = 0
$i++
"Test{0:00#}" -f $i

will give you

Test001

making use of a format string with desired padding of zeros.

Sign up to request clarification or add additional context in comments.

2 Comments

This is good, but then I need to be able to pass "Test001" as a value for $buildID
@Spawned18 Just do $buildID = "Test{0:00#}" -f $i then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.