src/utility/ConvertTo-EnumFlag.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# TODO: look into EnumConverter to see if it can be used here
# https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.enumconverter?view=netframework-4.7.1

# Must be called as the following (note the parentheses)
# ConvertTo-EnumFlag ([BackupPredicateEnum]::IsConfigFileValid)
function ConvertTo-EnumFlag {
    [CmdletBinding()]
    [OutputType([int])]
    Param(
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true)]
        [psobject]$InputObject,

        [Parameter(Mandatory = $true, Position = 0)]
        [enum]$Value
    )
    if ($InputObject -eq $true) {
        Write-Output $Value
    }
    else {
        Write-Output 0
    }
}