Private/Library/Get-EwLibraryRegistrationNameError.ps1

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

function Get-EwLibraryRegistrationNameError {
    [CmdletBinding()]
    [OutputType([string])]
    param([Parameter(Mandatory)][AllowEmptyString()][string]$Name)

    if ([string]::IsNullOrWhiteSpace($Name)) { return 'Enter a name for the Library registration.' }
    if ($Name.Length -gt 255 -or $Name -in @('.', '..') -or
        $Name.IndexOfAny([IO.Path]::GetInvalidFileNameChars()) -ge 0 -or $Name.TrimEnd(' ', '.') -ne $Name -or
        $Name -match '^(CON|PRN|AUX|NUL|CONIN\$|CONOUT\$|COM[1-9\u00B9\u00B2\u00B3]|LPT[1-9\u00B9\u00B2\u00B3])(\.|$)') {
        return "Invalid application folder name: '$Name'. Use a valid Windows folder name without trailing spaces or periods or reserved device names."
    }
    return ''
}