Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Read-Host & Adding Variables Together

$
0
0

 

Hello,

I'm not sure whether I am missing a trick here but I seem to be having difficulties passing a number to a variable using 'read-host' and then adding another number to that variable, rather than add the numbers up powershell concatenates them.

 

For example:

$num = read-host "Enter a number: " (I enter 5)

$num1 = read-host "Enter another number: " ( I enter 7)

$sum = $num + $num1

write-host $sum

 

The out put I get from this simple example is 57 rather than 12

 

Any help would be appreciated, although I’m sure this is really easy and will kick myself when I find the answer out!

 

Thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles