Solved PowerShell programing: simple issue

rahul1911

Member
My apologies if this is not the correct place to put up this question, but i saw that the PowerShell section is archived now, so had to put in here.

I am very new to the Powershell programing and trying out a very simple thing but failing.
Situation : for some code I am trying to compare two different integer values and getting the wrong result, below is the simulated code for :
************************************
[int] $a=5
[int] $b=3
if($a > $b)
{write-host "working"}
else
{write-host "not working"}
************************************
Now my problem is that when i press enter it prints "not working", which would mean that value b> value a, which is incorrect. Am I going wrong somewhere?
Please help.

Thanks
 

My Computer

this is the exact copy paste of the output from the PowerShell console Window :


PS C:\Documents and Settings\abc> [int] $a =5
___________________________________________________________________________________________________________________________
PS C:\Documents and Settings\abc> [int] $b =3
___________________________________________________________________________________________________________________________
PS C:\Documents and Settings\abc> if($a > $b)
{write-host "working"}
else
{write-host "not working"}
not working
 

My Computer

Hello, and welcome to the Vista Forums!

This may seem a little odd to begin with. ">" is not actually valid in Power Shell. You have to do something very strange!

Here is your code, corrected:

Code:
[int] $a=5
[int] $b=3
if($a -gt $b)
{write-host "working"}
else
{write-host "not working"}
Output:

Code:
________________________________________________________________________________________________________________________________________________________________________
PS C:\Users\Richard\Documents> C:\Users\Richard\Documents\test.ps1
working

________________________________________________________________________________________________________________________________________________________________________

You are probably now thinking "what on earth"!

-gt: Greater than.
-cgt: Case sensitive greater than

Have a look at this webpage: A Quick guideline for Microsoft Windows PowerShell Part-1. - CodeProject

In particular, look at the table of comparators near the bottom.

Persevere, and you will be rewarded! Have fun, and good luck!

Richard
 

My Computer

System One

  • Manufacturer/Model
    Dell XPS 420
    CPU
    Intel Core 2 Quad Q9300 2.50GHz
    Motherboard
    Stock Dell 0TP406
    Memory
    4 gb (DDR2 800) 400MHz
    Graphics Card(s)
    ATI Radeon HD 3870 (512 MBytes)
    Sound Card
    Onboard
    Monitor(s) Displays
    1 x Dell 2007FP and 1 x (old) Sonic flat screen
    Screen Resolution
    1600 x 1200 and 1280 x 1204
    Hard Drives
    1 x 640Gb (SATA 300)
    Western Digital: WDC WD6400AAKS-75A7B0

    1 x 1Tb (SATA 600)
    Western Digital: Caviar Black, SATA 6GB/S, 64Mb cache, 8ms
    Western Digital: WDC WD1002FAEX-00Z3A0 ATA Device
    PSU
    Stock PSU - 375W
    Case
    Dell XPS 420
    Cooling
    Stock Fan
    Keyboard
    Dell Bluetooth
    Mouse
    Advent Optical ADE-WG01 (colour change light up)
    Internet Speed
    120 kb/s
    Other Info
    ASUS USB 3.0 5Gbps/SATA 6Gbps - PCI-Express Combo Controller Card (U3S6)
Hello Richard,

To be true I had the exact feeling once I saw your reply.

you are a real help, thanks for your reply on this, really thankfull for the information.
 

My Computer

Hello Richard,

To be true I had the exact feeling once I saw your reply.

you are a real help, thanks for your reply on this, really thankfull for the information.

It is not an issue, and you are most welcome!

-gt is ... guessable :sarc: :confused: :sick: :shock: :eek: :rolleyes: :zip:
 

My Computer

System One

  • Manufacturer/Model
    Dell XPS 420
    CPU
    Intel Core 2 Quad Q9300 2.50GHz
    Motherboard
    Stock Dell 0TP406
    Memory
    4 gb (DDR2 800) 400MHz
    Graphics Card(s)
    ATI Radeon HD 3870 (512 MBytes)
    Sound Card
    Onboard
    Monitor(s) Displays
    1 x Dell 2007FP and 1 x (old) Sonic flat screen
    Screen Resolution
    1600 x 1200 and 1280 x 1204
    Hard Drives
    1 x 640Gb (SATA 300)
    Western Digital: WDC WD6400AAKS-75A7B0

    1 x 1Tb (SATA 600)
    Western Digital: Caviar Black, SATA 6GB/S, 64Mb cache, 8ms
    Western Digital: WDC WD1002FAEX-00Z3A0 ATA Device
    PSU
    Stock PSU - 375W
    Case
    Dell XPS 420
    Cooling
    Stock Fan
    Keyboard
    Dell Bluetooth
    Mouse
    Advent Optical ADE-WG01 (colour change light up)
    Internet Speed
    120 kb/s
    Other Info
    ASUS USB 3.0 5Gbps/SATA 6Gbps - PCI-Express Combo Controller Card (U3S6)
Back
Top