TabExpansion.ps1

try
{
    Import-Module -Name TabExpansionPlusPlus -ea Ignore
    if (Get-Command Register-ArgumentCompleter -Module TabExpansionPlusPlus -ea Ignore)
    {
        # http://www.powertheshell.com/dynamicargumentcompletion/
        # https://github.com/lzybkr/TabExpansionPlusPlus
        Register-ArgumentCompleter -CommandName Get-KPEntry -ParameterName "KeyPassFile" -ScriptBlock {
            param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
            Import-Module (Join-Path $PSScriptRoot common\common.psm1) -Prefix KP 
            $path = Get-KPParamHistory -Function Get-KPEntry -Parameter KeyPassFile
            if ($path)
            {
                $path | % { New-CompletionResult -CompletionText "'$($_.Content)'" -ListItemText $($_.Content) }
            }
        }
    }
    elseif (Get-Command Register-ArgumentCompleter -Module Microsoft.PowerShell.Core -ea Ignore)
    {
        #https://technet.microsoft.com/en-us/library/mt631420.aspx

        Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName Get-KPEntry -ParameterName "KeyPassFile" -ScriptBlock { Get-KPParamHistory -Function Get-KPEntry -Parameter KeyPassFile | % {$_.Content} }
    }
}
catch
{
    Write-KPLog -message $_ -Level EXCEPTION
}