January 28th, 2016

PowerTip: Add number to existing variable value

Doctor Scripto
Scripter

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

8

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback