Recently, I got a requirement from one of my clients to increment a string variable that represents a version number in PowerShell. This is a little tricky, but there is a way to do it. In this tutorial, I will show you how to increment a string variable by 1 in PowerShell.
To increment a string variable with a numeric suffix in PowerShell, you can split the string into parts, convert the numeric portion to an integer, increment it, and then reassemble the string. For example, given a version number “1.0.0”, you can use the following script:
$version = "1.0.0"
$parts = $version.Split('.')
$parts[2] = [int]$parts[2] + 1
$newVersion = "$($parts[0]).$($parts[1]).$($parts[2])"
Write-Output $newVersion # Outputs "1.0.1"This method ensures the numeric portion is correctly incremented while preserving the original format.
Now, let me show you how to increment a string variable in PowerShell.
Method 1: Numeric Suffix Increment
The simplest form of string incrementation involves a numeric suffix. This is particularly useful for creating unique identifiers or version numbers.
Example: Incrementing a Version Number
Let’s say you have a version number stored as a string, such as “1.0.0”. You can increment the last part of the version number using the following script:
$version = "1.0.0"
$parts = $version.Split('.')
$parts[2] = [int]$parts[2] + 1
$newVersion = "$($parts[0]).$($parts[1]).$($parts[2])"
Write-Output $newVersion # Outputs "1.0.1"In this example, we split the version number into an array, increment the last element, and then reassemble the string.
I executed the above PowerShell script, and you can see the output in the screenshot below:

Check out PowerShell Print Variable
Method 2: Alphabetic Increment
Incrementing alphabetic characters in PowerShell is more complex than numeric increments. This method is useful when you need to cycle through letters, such as in column naming (A, B, C, …, Z, AA, AB, etc.).
Example: Incrementing Column Names
Here’s a PowerShell script that increments alphabetic characters:
function Increment-Alpha {
param (
[string]$input
)
$charArray = $input.ToCharArray()
for ($i = $charArray.Length - 1; $i -ge 0; $i--) {
if ($charArray[$i] -ne 'Z') {
$charArray[$i] = [char]([int][char]$charArray[$i] + 1)
return -join $charArray
} else {
$charArray[$i] = 'A'
if ($i -eq 0) {
return 'A' + (-join $charArray)
}
}
}
}
$column = "Z"
$newColumn = Increment-Alpha $column
Write-Output $newColumn # Outputs "AA"This function increments a string of alphabetic characters, handling the carry-over when a ‘Z’ is encountered.
Method 3: Custom String Patterns
For more complex scenarios, you might need to increment a string that contains both letters and numbers, or follows a custom pattern.
Example: Incrementing a Custom Identifier
Consider a scenario where you have an identifier like “ID-001” that you need to increment:
function Increment-Identifier {
param (
[string]$identifier
)
if ($identifier -match '^(.*?)(\d+)$') {
$prefix = $matches[1]
$number = [int]$matches[2] + 1
return "$prefix$($number.ToString('D3'))"
} else {
throw "Identifier format not recognized"
}
}
$id = "ID-001"
$newId = Increment-Identifier $id
Write-Output $newId # Outputs "ID-002"This function uses a regular expression to separate the prefix from the numeric part, increments the number and then reassembles the string.
You can see the exact output in the screenshot below:

In this tutorial, I explained how to increment string variable by 1 in PowerShell with a few examples.
You may also like:
- How to Convert a String to Title Case in PowerShell?
- How to Find a String in a File and Return the Line Using PowerShell?
- PowerShell String Replace
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.