examples/06-Export-Everything.ps1
|
# 06 - Get your data OUT of Access: every table of a database as CSV and JSON, ready for Excel, SharePoint, # SQL, Power BI or a web page. Schedule it on a Linux server and the export runs every night without Access. # ./06-Export-Everything.ps1 -Database ./Legacy.mdb -Out ./export param([string] $Database = (Join-Path (Join-Path ([IO.Path]::GetTempPath()) 'kAccess-examples') 'Sales.accdb'), [string] $Out = (Join-Path (Join-Path ([IO.Path]::GetTempPath()) 'kAccess-examples') 'export')) Import-Module kAccess New-Item $Out -ItemType Directory -Force | Out-Null foreach ($Table in Get-kAccessTable $Database) { $Rows = @(Get-kAccessRow $Database $Table.Name | Select-Object -ExcludeProperty kAccessRowId) $Rows | Export-Csv (Join-Path $Out "$($Table.Name).csv") ConvertTo-Json @($Rows) -Depth 3 | Set-Content (Join-Path $Out "$($Table.Name).json") "{0,-20} {1,6} rows -> {0}.csv, {0}.json" -f $Table.Name, $Rows.Count } |