Public/Get-DbaseColumnMetaData.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
function Get-DbaseColumnMetaData {
    <#
    .SYNOPSIS
    Displays metadata for Dbase columns
 
    .DESCRIPTION
    Displays metadata for Dbase columns
 
    .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 ColumnName
    What is the name of the column(s) of interest? Null means 'all tables'.
 
    .EXAMPLE
    Get-DbaseColumnMetaData -datasource '\\server\share\path'
    # Shows all of the columns in the tables at that location.
 
    .EXAMPLE
    Get-DbaseColumnMetaData -datasource '\\server\share\path' -TableName "dept"
    # Shows the column information for all of the columns in the table named 'dept'.
 
    .EXAMPLE
    Get-DbaseColumnMetaData -datasource '\\server\share\path' -ColumnName "fname"
    Shows the column information for the column 'fname' in all tables found at that location.
    This can be very handy to look for differences in column definitions.
 
    #>


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

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

        # Get-OleDbColumnMetadata doesn't provide for restricting by column name, so we will do that here.
        # Dbase doesn't support many of the metadata columns here, so we will restrict the output
        Get-OleDbColumnMetadata -Connection $cn |
            Where-Object { $_.ColumnName -eq $ColumnName -or $Null -eq $ColumnName } |
            Select-Object TableName,
            ColumnName, OrdinalPosition,
            ColumnFlags,
            IsNullable,
            DataType, DataTypeDescription,
            NumericPrecision, NumericScale,
            CharacterMaximumLength, CharacterOctetLength
        # TableCatalog, TableScema
        # ColumnHasDefault, ColumnDefault,
        # CharacterSetCatalog, CharacterSetSchema, CharacterSetName,
        # CollationCatalog, CollationSchema, CollationName,
        # DomainCatalog, DomainSchema, DomainName,
        # IsComputed
    }

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

}