Install and Use kAccess
Seven Ready-Made Examples Included
kAccess installs from the PowerShell Gallery with one command and takes a few seconds. Nothing else is installed: no driver, no runtime and no service. You need PowerShell 7.2 or later on Windows, Linux or macOS. Microsoft Access, the Access Database Engine, ODBC and Java are not needed.
Install kAccess
- Open PowerShell 7 (type
pwsh in a terminal).
- Run the install command:
Install-PSResource kAccess -Repository PSGallery -TrustRepository
On PowerShell 7.2 and 7.3, use Install-Module kAccess instead and answer Y when you are asked to trust the gallery.
- Check that PowerShell finds the module and its 18 commands:
Get-Module kAccess -ListAvailable
Get-Command -Module kAccess
The module is installed for the current user, so no administrator rights are needed. Add -Scope AllUsers in an elevated session to install it for every user of the computer.
Your first database
Four commands create an Access database with a table, add two contacts and read them back:
New-kAccessDatabase ./Contacts.accdb
New-kAccessTable ./Contacts.accdb Contacts -Column `
@{ Name = 'Id'; Type = 'LONG'; AutoNumber = $true },
@{ Name = 'Name'; Type = 'TEXT'; Length = 60 },
@{ Name = 'Email'; Type = 'TEXT'; Length = 120 },
@{ Name = 'Added'; Type = 'SHORT_DATE_TIME' } `
-Index @{ Name = 'PrimaryKey'; Columns = @('Id'); PrimaryKey = $true }
Add-kAccessRow ./Contacts.accdb Contacts -Row `
@{ Name = 'Ada Lovelace'; Email = 'ada@example.com'; Added = Get-Date },
@{ Name = 'Alan Turing'; Email = 'alan@example.com'; Added = Get-Date }
Get-kAccessRow ./Contacts.accdb Contacts | Format-Table Id, Name, Email, Added
The result is an ordinary .accdb file that you can open in Microsoft Access. Rows from Get-kAccessRow can be piped straight on to Set-kAccessRow or Remove-kAccessRow to change or delete them.
Seven ready-made examples
kAccess comes with seven complete scripts in its examples folder. Each one runs as it is and is a good start for your own script:
- 01-Quick-Start: A new database with a table, an AutoNumber key and rows – in 30 seconds.
- 02-Csv-To-Access: Any CSV file as an Access table. The column types are worked out from the data, and all rows go in with one bulk write.
- 03-Sales-Database: Customers and Orders with primary keys, a unique e-mail index and a relationship, plus a sales report per customer. A duplicate e-mail is refused, and nothing of that batch is written.
- 04-Maintain-Data: Change and delete hundreds of rows with one pipeline, rename and drop tables.
- 05-Database-Inventory: Every table, column and row count of all .accdb and .mdb files in a folder tree – before a migration or a clean-up.
- 06-Export-Everything: Every table of a database as CSV and JSON, ready for Excel, SharePoint, SQL or Power BI.
- 07-Convert-Format: A whole database copied into another Access format, for example .accdb to an Access 2000 .mdb.
Copy them to a folder of your own before you run or change them, so an update of the module never overwrites your changes:
Copy-Item -Recurse (Join-Path (Get-Module kAccess -ListAvailable).ModuleBase examples) .
cd examples
./01-Quick-Start.ps1
Update and remove
- Update to the newest version:
Update-PSResource kAccess
- Remove the module:
Uninstall-PSResource kAccess
More info
|