functions/Test-DBOSupportedSystem.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Function Test-DBOSupportedSystem {
    <#
    .SYNOPSIS
    Test if module is ready to work with certain RDBMS
     
    .DESCRIPTION
    Test if access to a certain RDBMS is currently supported by the module by checking if all the dependencies have been installed
     
    .PARAMETER Type
    RDBMS Type: Oracle, SQLServer
     
    .EXAMPLE
    #Tests if all dependencies for Oracle have been met
    Test-DBOSupportedSystem Oracle
    .NOTES
     
    #>

    Param (
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            Position = 1)]
        [Alias('System', 'Database')]
        [ValidateSet('SQLServer', 'Oracle')]
        [string]$Type
    )
    begin {}
    process {
        $dependencies = Get-ExternalLibrary -Type $Type
        foreach ($package in $dependencies) {
            $packageFound = [bool](Get-Package $package.Name -MinimumVersion $package.Version -ErrorAction SilentlyContinue)
            if (!$packageFound) {
                Write-Warning -Message "Dependent packages for $Type were not found. Run Install-DBOSupportLibrary -Type $Type"
                return $false
            }
        }
        return $true
    }
    end {}
}