Functions/ConvertFrom-SymbolSeparatedValues.ps1

<#
.SYNOPSIS
    This function converts a single set of values separated by a symbol into a list of the values.
#>


function ConvertFrom-SymbolSeparatedValues {
    [CmdletBinding(PositionalBinding=$true)]
    [OutputType([String[]])]
    param (
        # The values to convert.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$values,

        # The symbol used to separate the values.
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        [String]$symbol,

        # Select whether to trim the values.
        [Parameter(Mandatory=$false)]
        [Switch]$trimValues = [Switch]::Present,

        # Select whether to ignore null/whitespace values.
        [Parameter(Mandatory=$false)]
        [Switch]$ignoreNullOrWhitespace = [Switch]::Present
    )

    # Split the values
    $splitValues = $values.Split($symbol)

    # Process the values
    if ($trimValues) {
        $splitValues = $splitValues | ForEach-Object -Process { $_.Trim() }
    }
    if ($ignoreNullOrWhitespace) {
        $splitValues = $splitValues | Where-Object { ![String]::IsNullOrWhiteSpace($_) }
    }

    # Return the values
    return ConvertTo-Array $splitValues
}