mao
10/28/2012 - 12:47 AM

Convert common values to Powershell boolean values $true and $false

Convert common values to Powershell boolean values $true and $false

function ConvertTo-Boolean
{
  param
  (
    [Parameter(Mandatory=$false)][string] $value
  )
  switch ($value)
  {
    "y" { return $true; }
    "yes" { return $true; }
    "true" { return $true; }
    "t" { return $true; }
    1 { return $true; }
    "n" { return $false; }
    "no" { return $false; }
    "false" { return $false; }
    "f" { return $false; } 
    0 { return $false; }
  }
}