Private/DBUtil.ps1

function Get-LegacyDatabaseConfig($Role) {
    $path = Get-LegacyDBConfigPath $Role
    if (Test-Path $path) {
        [xml]$dbConfigReader = Get-Content $path
        $dbConfig = @{
            Server = $dbConfigReader.DataConnectionConfig.serversList.Server.name;
            Database = $dbConfigReader.DataConnectionConfig.serversList.Server.databasesList.Database.name;          
        }
        
        Write-Verbose "Database configuration found and read"
        return $dbConfig
    } else {
        Write-Warning "No database configuration $path"
        return $null
    } 
}

function Get-ConnectionString(
    $Server,
    $Database,
    $IntegratedSecurity,
    $Login,
    $Password) {
        return "Server=$Server;Database=$Database;User ID=$Login;Password=$Password;Integrated Security=$IntegratedSecurity"
}

function Get-DatabaseData {
    [CmdletBinding()]
    param (
        [string]$connectionString,
        [string]$query,
        [switch]$isSQLServer
    )
    if ($isSQLServer) {
        Write-Verbose 'in SQL Server mode'
        $connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
    } else {
        Write-Verbose 'in OleDB mode'
        $connection = New-Object -TypeName System.Data.OleDb.OleDbConnection
    }
    $connection.ConnectionString = $connectionString
    $command = $connection.CreateCommand()
    $command.CommandText = $query
    if ($isSQLServer) {
        $adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command
    } else {
        $adapter = New-Object -TypeName System.Data.OleDb.OleDbDataAdapter $command
    }
    $dataset = New-Object -TypeName System.Data.DataSet
    $adapter.Fill($dataset)
    $dataset.Tables[0]
}
function Invoke-DatabaseQuery {
    [CmdletBinding()]
    param (
        [string]$connectionString,
        [string]$query,
        [switch]$isSQLServer
    )
    if ($isSQLServer) {
        Write-Verbose 'in SQL Server mode'
        $connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
    } else {
        Write-Verbose 'in OleDB mode'
        $connection = New-Object -TypeName System.Data.OleDb.OleDbConnection
    }
    $connection.ConnectionString = $connectionString
    $command = $connection.CreateCommand()
    $command.CommandText = $query
    $connection.Open()
    $command.ExecuteNonQuery()
    $connection.close()
}