Public/Compare-DbaseTableMetaData.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function Compare-DbaseTableMetaData {
    <#
    .SYNOPSIS
    Simple comparison of tables in a pair of (or the same) Dbase databases.
 
    .DESCRIPTION
    Simple comparison of tables in a pair of (or the same) Dbase databases.
 
    .PARAMETER SourcePath
    The path of the 'source' database.
 
    .PARAMETER TargetPath
    The path of the 'target' database.
 
    .PARAMETER TableName
    What table or tables would you like to compare? This uses -match semantics; it is not an array of table names.
 
    .PARAMETER Provider
    What describes the provider? Often this, is the guts that describe a "dsn-less" connection. It is used to choose the drivers that will be used to do to work of retrieving the data.
 
    .PARAMETER IncludeEqual
    Should tables that are "equal", or the same, be shown in the output? Default is $true.
 
    .PARAMETER ExcludeDifferent
    Should tables that are "equal", or are different, be shown in the output? Default is $false.
 
    .EXAMPLE
    Compare-DbaseTableMetaData -source:"c:\Dbase" -target:"C:\Dbase_copy"
 
    This example shows how to query an access database.
 
 
    .LINK
    Get-DbaseTable
    #>

    param (
        [Parameter(Mandatory = $true)]
        [string] $SourcePath,

        [Parameter(Mandatory = $true)]
        [string] $TargetPath,

        [Parameter(Mandatory = $true)]
        [string] $Provider,

        [Parameter(ValueFromPipeline = $True, ValueFromPipelinebyPropertyName = $True)]
        [string] $TableName = ".*",

        [switch] $IncludeEqual,

        [switch] $ExcludeDifferent
    )

    process {
        # Get the objects for the source and target
        $r1 = Get-DbaseTableMetaData -Path $SourcePath -TableName $TableName
        $r2 = Get-DbaseTableMetaData -Path $TargetPath -TableName $TableName

        # compare the reports and send the output down the pipeline.
        Compare-Object $r1 $r2 -SyncWindow:(($r1.count + $r2.count) / 2) -Property 'TableName' -IncludeEqual $IncludeEqual -ExcludeDifferent $ExcludeDifferent -PassThru |
            Select-Object @{Name = 'ObjectType'; e = { "Table" } }, TableName,
            @{Name = 'SourcePath'; e = { $SourcePath } },
            SideIndicator,
            @{Name = 'TargetPath'; e = { $TargetPath } }
    }

}