param (
        $server = "igori", #Имя компьютера сервера
        $source="D:\Share\Data50enc", #Путь до каталога с шифрованными базами 
        $swbuild = "D:\Program Files (x86)\Wizardsoft\SWBASES_50.SWL", #Полный путь до файла с файлом SWBASES
        $port = 3051, #Порт на котором работает сервер
        $provider = "$PSScriptRoot\FirebirdSql.Data.FirebirdClient.dll", #Путь до клиента FB C#
        $ClientLibrary = "$PSScriptRoot\..\SmetaWIZARD_5.1.1.17_x64\fbclient.dll", #Путь до клиента FB
        $pattern = "\.(db5exp|db5prc|db5ind|db5doc|db5ic|db5gf|db5rc)$" #Здесь все правильно
)

$usr = "*"
$types = @{
    ".db5exp"  = 10
    ".db5prc"  = 20
    ".db5ind"  = 50
    ".db5doc"  = 60
    ".db5ic" = 30
    ".db5gf" = 70
	".db5rc" = 120
}

$s_cmd_Clear = @"
    delete from SWDBS
"@
$s_cmd_add = @"
    insert into SWDBS (path, type, usr)
    values (@path, @type, @usr)
"@

$files = Get-ChildItem -Recurse -LiteralPath $source | ?{$_.extension -match $pattern}

Add-Type -LiteralPath $provider

$ConnectionBuilder = New-Object FirebirdSql.Data.FirebirdClient.FbConnectionStringBuilder
$ConnectionBuilder.Pooling = $false
$ConnectionBuilder.UserID = "sysdba"
$ConnectionBuilder.Password = "masterkey"
$ConnectionBuilder.DataSource = "localhost"
#$ConnectionBuilder.Database = "swbases"
$ConnectionBuilder.Database = $swbuild
$ConnectionBuilder.Port = $port
$ConnectionBuilder.ClientLibrary = $clientLibrary
$ConnectionBuilder.Dialect = 3
$ConnectionBuilder.Charset = "UTF8"
$ConnectionBuilder.ServerType = [FirebirdSql.Data.FirebirdClient.FbServerType]::Embedded

if ($files.Count -eq 0)
{
    throw "Нет файлов для формирования списка"
}

try
{
    $connection = New-Object FirebirdSql.Data.FirebirdClient.FbConnection($ConnectionBuilder.ConnectionString)
    $connection.Open()

    $command = $connection.CreateCommand()
    $command.CommandText = $s_cmd_Clear

    $command.ExecuteNonQuery() | Out-Null

    $command.CommandText = $s_cmd_add

    $count = 0
    $files |
    %{
        $filename = $_.FullName
        $serverfilename = "$server/$($port):$filename"
        $ext = [IO.Path]::GetExtension($filename)
        $type = $types[$ext]

        $filename
        $count++
        $command.Parameters.Clear()
        $command.Parameters.Add("@path", $serverfilename) | Out-Null
        $command.Parameters.Add("@type", $type) | Out-Null
        $command.Parameters.Add("@usr", $usr) | Out-Null
        
        $command.ExecuteNonQuery() | Out-Null
    }
}
finally
{
    if ($connection.State -eq [Data.ConnectionState]::Open)
    {
        $connection.Close()
    }
}

"Зарегистрировано баз: $count"