1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add ConvertTo-Bool filter function in powershell common code

This commit is contained in:
Matt Martz 2014-06-19 10:36:53 -05:00
parent 04d94ffb8f
commit 90c98ada7c

View file

@ -64,3 +64,26 @@ Function Fail-Json($obj, $message)
echo $obj | ConvertTo-Json echo $obj | ConvertTo-Json
Exit 1 Exit 1
} }
# Helper filter/pipeline function to convert a value to boolean following current
# Ansible practices
Function ConvertTo-Bool
{
param(
[parameter(valuefrompipeline=$true)]
$obj
)
$boolean_strings = "yes", "on", "1", "true", 1
$obj_string = [string]$obj
if (($obj.GetType().Name -eq "Boolean" -and $obj) -or $boolean_strings -contains $obj_string.ToLower())
{
$true
}
Else
{
$false
}
return
}