statement if (61>0){...} does not work :(

rated by 0 users
This post has 2 Replies | 1 Follower

Not Ranked
Posts 1
Buchas Posted: 05-06-2012 6:44 AM

Hello,

I have the following code inside a ps1 file:

---

$errorString = ($root.fault.value.struct.member | Where-Object { $_.name -match "faultString" }).value.string

if(($errorString.length) > 0){ 

    Write-Debug ("ERROR_NOT_PRINTED: " + $errorString )

}

Write-Debug ("ERROR: length: " + ($errorString.length) )

Write-Debug ("ERROR: " + $errorString)

---

The debug output shows:

DEBUG: ERROR: length: 61

DEBUG: ERROR: Parameter that is supposed to be floating point number is not

Why doesn't it show the  ERROR_NOT_PRINTED string? Its length is 61 which is bigger than zero ... 

Top 75 Contributor
Posts 38

You'd better double check what operation you want.

I believe you want

if($errorString -gt 0) {

And if you check (51 > 0) and assign it to a variable, it turns into...

$null

Check your current directory, and you'll find out that you've created a file name 0 with the string length in it.

Top 100 Contributor
Posts 33

check out the about_Comparison_operators: http://technet.microsoft.com/en-us/library/dd315321.aspx

Powershell does not use ">", instead it uses the "-gt" operator.

 

Page 1 of 1 (3 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.