Link to home
Start Free TrialLog in
Avatar of lvpropc
lvpropc

asked on

Powershell script strange behavior

I'm experiencing strange behavior with a simple powershell script.

$number = read-host "enter 50"
$guess = read-host "enter 100"

if ($guess -lt $number){
write-host "$guess is less than $number"}
else{
write-host "$guess is greater than $number"}

This script should go to the else statement when entering in 50 and 100 as directed but it doesn't and I can't figure out why. Any input would be much appreciated.

On a side note. After running the script I can in type in powershell
$guess -lt $number and get false which is as expected.
ASKER CERTIFIED SOLUTION
Avatar of Justin Yeung
Justin Yeung
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"On a side note. After running the script I can in type in powershell
$guess -lt $number and get false which is as expected."


That's not true, as the result is still $true when using the read-host results. However, if you assign numeric literals 50 and 100, the condition is $false now.
Avatar of lvpropc
lvpropc

ASKER

You're right Qlemo in my powershell session I had previously assigned the INT's to the variables in order to get the false result. After restarting my session it displayed the incorrect result. The irony is the book I'm reading on powershell has this script in it as a working model. Someone needs to fire the author and editor.