newbie question on function return values

This topic contains 2 replies, has 3 voices, and was last updated by  Sam Boutros 3 weeks, 4 days ago.

  • Author
    Posts
  • #92156

    SteveG
    Participant

    All, trying to develop a simple function that does an evaluation and returns $true or $false, but the result always returns $false. What's up with that? Am I doing something stupid here? The code works outside of the function.

    $var = 'VDI'
    
    function is_billable([String]$cb)
    {
    $list = [String]"'VDI','MOD','MDI'"
    if($list -match $cb) {
    	 $result =$true
    }
    else {
    	 $result = $false
    }
    return $result
    }
    
    $test = is_billable($var)
    
    

    – always comes back false

  • #92164

    random commandline
    Participant

    Try this. Your $list variable is a string object not an array.

    function is_billable([String]$cb)
    {
    $list = [String]'VDI','MOD','MDI'
    if($list -contains $cb) {$true} else {$false}
    }
    
    $test = is_billable($var)
    
  • #92177

    Sam Boutros
    Participant
    function is_billable([String]$cb) { @('VDI','MOD','MDI') -contains $cb }
    

    not case sensitive

You must be logged in to reply to this topic.