Public/Get-DbaseIndexMetaData.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
70
71
72
73
74
75
76
77
function Get-DbaseIndexMetaData {
    <#
    .SYNOPSIS
    Displays metadata for Dbase indexes
 
    .DESCRIPTION
    Displays metadata for Dbase indexes
 
    .NOTES
    For what it is worth, Dbase does not seem to support "keys", either primary keys or alternate keys.
    It does support indexes. There are columns in the output that indicate uniqueness, etc.
 
    .PARAMETER DataSource
    Which Dbase location is of interest?
 
    .PARAMETER TableName
    What is the name of the table(s) of interest? Null means 'all tables'.
 
    .PARAMETER IndexName
    What is the name of the index(es) of interest? Null means 'all indexes'.
 
    .EXAMPLE
    Get-DbaseIndexMetaData -datasource '\\server\share\path'
    # Shows all of the primary keys for the tables at that location.
 
    .EXAMPLE
    Get-DbaseIndexMetaData -datasource '\\server\share\path' -TableName "dept"
    # Shows all of the primary keys for the named table at that location.
    #>


    param (
        [Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelinebyPropertyName = $True)]
        [string] $Datasource,
        [string] $TableName,
        [string] $IndexName
    )

    try {
        $cn = Get-DbaseConnection -DataSource $Datasource

        # Not all of the columns that OleDbSchemaIndex returns are useful/valid/supported in Dbase
        # and I commented those out.
        Get-OleDbIndexMetadata -Connection $cn -TableName $TableName -IndexName $IndexName |
            Select-Object TableName,
            # TableCatalog,
            # TableSchema,
            # IndexCatalog,
            # IndexSchema,
            IndexName,
            PrimaryKey,
            Unique,
            # Clustered,
            Type,
            # FillFactor,
            # InitialSize,
            Nulls,
            SortBookmarks,
            # AutoUpdate,
            NullCollation,
            OrdinalPosition,
            ColumnName,
            # ColumnGuid,
            # ColumnPropID,
            Collation,
            Cardinality,
            # Pages,
            # FilterCondition,
            Integrated,
            Expression
    }

    finally {
        $cn.Close()
        $cn.Dispose()
    }

}