How to validate PowerShell Function Parameters allowing empty strings?

The Mandatory attribute blocks null and empty values and prompts you for a value.
To allow empty values (including null) add the AllowEmptyString parameter attribute:

function f1
{
    param(
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
    [string]$Text
    )
    $text
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)