PowerTip: Add number to existing variable value

Summary: Learn how to easily add a number to an existing value stored in a variable and update the value of the variable.

Hey, Scripting Guy! Question How can I use Windows PowerShell to add a number to a value stored in a variable so that I can update the
           value in that variable with the number and store the number back into the variable?

Hey, Scripting Guy! Answer Use the += operator. This example adds 3 to the value stored in the $a variable and then stores the new
           value back into the variable:

PS C:\> $a = 5

PS C:\> $a += 3

PS C:\> $a


Comments (0)

Skip to main content