Author Posts

January 25, 2018 at 12:07 am

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

January 25, 2018 at 3:06 am

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)

January 25, 2018 at 9:08 am

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

not case sensitive