newbie question on function return values

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

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)
function is_billable([String]$cb) { @('VDI','MOD','MDI') -contains $cb }

not case sensitive