examples/05-Database-Inventory.ps1

# 05 - Inventory every Access database in a folder tree: each file, its tables, columns and row counts.
# Old .mdb files from Access 2000 and 2003 work as well as .accdb. Great before a migration or a clean-up.
# ./05-Database-Inventory.ps1 -Path \\server\share\departments
param([string] $Path = (Join-Path ([IO.Path]::GetTempPath()) 'kAccess-examples'))
Import-Module kAccess
$Report = foreach ($File in Get-ChildItem $Path -Recurse -File -Include *.accdb, *.mdb) {
    try {
        foreach ($Table in Get-kAccessTable $File.FullName) {
            [pscustomobject] @{
                File    = $File.Name
                Table   = $Table.Name
                Rows    = $Table.RowCount
                Columns = $Table.Columns.Count
                Keys    = ($Table.Indexes -join ', ')
                SizeMB  = [math]::Round($File.Length / 1MB, 2)
            }
        }
    } catch {
        [pscustomobject] @{ File = $File.Name; Table = '(cannot be read)'; Rows = $null; Columns = $null; Keys = $_.Exception.Message; SizeMB = [math]::Round($File.Length / 1MB, 2) }
    }
}
$Report | Format-Table File, Table, Rows, Columns, Keys, SizeMB
$Report | Export-Csv (Join-Path $Path 'access-inventory.csv')
"Inventory saved as access-inventory.csv in $Path"