• Stars
    star
    287
  • Rank 139,569 (Top 3 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created about 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PowerShell module to query SQLite databases

Build status

PSSQLite PowerShell Module

This is a PowerShell module for working with SQLite. It uses similar syntax to the Invoke-Sqlcmd2 function from Chad Miller et al.

This covers limited functionality; contributions to this function or additional functions would be welcome!

Caveats:

  • Minimal testing.
  • Today was my first time working with SQLite

Functionality

Create a SQLite database and table:

  • Create a SQLite database and table

Query a SQLite database, using parameters:

  • Query a SQLite database

Create a SQLite connection, use it for subsequent queries:

  • Create a SQLite connection, use it

Insert large quantities of data quickly with transactions (why?):

  • Insert large quantities of data quickly

Instructions

# One time setup
    # Download the repository
    # Unblock the zip
    # Extract the PSSQLite folder to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\)

    #Simple alternative, if you have PowerShell 5, or the PowerShellGet module:
        Install-Module PSSQLite

# Import the module.
    Import-Module PSSQLite    #Alternatively, Import-Module \\Path\To\PSSQLite

# Get commands in the module
    Get-Command -Module PSSQLite

# Get help for a command
    Get-Help Invoke-SQLiteQuery -Full

# Create a database and a table
    $Query = "CREATE TABLE NAMES (fullname VARCHAR(20) PRIMARY KEY, surname TEXT, givenname TEXT, BirthDate DATETIME)"
    $DataSource = "C:\Names.SQLite"

    Invoke-SqliteQuery -Query $Query -DataSource $DataSource

# View table info
    Invoke-SqliteQuery -DataSource $DataSource -Query "PRAGMA table_info(NAMES)"

# Insert some data, use parameters for the fullname and birthdate
    $query = "INSERT INTO NAMES (fullname, surname, givenname, birthdate) VALUES (@full, 'Cookie', 'Monster', @BD)"

    Invoke-SqliteQuery -DataSource $DataSource -Query $query -SqlParameters @{
        full = "Cookie Monster"
        BD   = (get-date).addyears(-3)
    }

# View the data
    Invoke-SqliteQuery -DataSource $DataSource -Query "SELECT * FROM NAMES"

#Build up some fake data to bulk insert, convert it to a datatable
    $DataTable = 1..10000 | %{
        [pscustomobject]@{
            fullname = "Name $_"
            surname = "Name"
            givenname = "$_"
            BirthDate = (Get-Date).Adddays(-$_)
        }
    } | Out-DataTable

#Insert the data within a single transaction (SQLite is faster this way)
    Invoke-SQLiteBulkCopy -DataTable $DataTable -DataSource $DataSource -Table Names -NotifyAfter 1000 -verbose

#View all the data!
    Invoke-SqliteQuery -DataSource $DataSource -Query "SELECT * FROM NAMES"

Notes

This isn't a fully featured module or function.

I'm planning to write about using SQL from a systems administrator or engineer standpoint. I personally stick to MSSQL and Invoke-Sqlcmd2, but want to provide an abstracted means to perform this without the prerequisite of an accessible MSSQL instance.

Check out Jim Christopher's SQLite PowerShell Provider. It offers more functionality and flexibility than this repository.

Credit to Chad Miller, Justin Dearing, Paul Bryson, Joel Bennett, and Dave Wyatt for the code carried over from Invoke-Sqlcmd2.

More Repositories

1

PowerShell

Various PowerShell functions and scripts
PowerShell
934
star
2

Invoke-Parallel

Speed up PowerShell with simplified multithreading
PowerShell
374
star
3

PSDeploy

Simple PowerShell based deployments
PowerShell
343
star
4

PSDepend

PowerShell Dependency Handler
PowerShell
273
star
5

PSSlack

PowerShell module for simple Slack integration
PowerShell
266
star
6

PSExcel

A simple Excel PowerShell module
PowerShell
243
star
7

BuildHelpers

Helper functions for PowerShell CI/CD scenarios
PowerShell
208
star
8

SecretServer

Secret Server PowerShell Module
PowerShell
87
star
9

PSStackExchange

PowerShell module to query Stack Exchange API
PowerShell
80
star
10

PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
PowerShell
45
star
11

PSHTMLTable

PowerShell module to spice up ad hoc notifications and reports
PowerShell
37
star
12

Git-Presentation

Presentation materials for Git and GitHub TechSession
33
star
13

WritingModules

Material accompanying PowerShell + DevOps Summit session
PowerShell
31
star
14

PSDiskPart

DiskPart PowerShell Module
PowerShell
31
star
15

Infoblox

Infoblox PowerShell Module
PowerShell
30
star
16

PSNeo4j

Simple Neo4j PowerShell Wrapper
PowerShell
29
star
17

ADGrouper

Define dynamic AD security group membership via yaml
PowerShell
18
star
18

Dots

A janky, neo4j based CMDB glued together with PowerShell
PowerShell
15
star
19

Citrix.NetScaler

PowerShell module for working with Citrix NetScaler REST API
PowerShell
15
star
20

PSRT

PowerShell wrapper for Request Tracker
PowerShell
10
star
21

TireFire

A janky PowerShell module to simplify managing notes and their metadata
PowerShell
7
star
22

PSStash

Atlassian Stash PowerShell Module
PowerShell
7
star
23

PSPagerDuty

Simple PowerShell PagerDuty module
PowerShell
7
star
24

PSLDAPQueryLogging

PowerShell module to simplify configuring AD LDAP diagnostic logging
PowerShell
7
star
25

PSPuppetDB

Simple module for querying the PuppetDB API
PowerShell
6
star
26

Wait-Path

Wait for a path to exist
PowerShell
5
star
27

CommunityLightningDemos2017

Proposals, and eventually demo material for Community Lightning Demos
PowerShell
5
star
28

PSSensu

Simple PowerShell module for working with the Sensu Go API
PowerShell
3
star
29

SessionMaterials

Materials or links to materials from sessions I've participated in
PowerShell
3
star
30

AppVeyor-DSC-Test

POC to test DSC configurations on a fresh VM from AppVeyor
PowerShell
2
star
31

AppVReporting

App-V Reporting PowerShell Module
PowerShell
2
star
32

RamblingCookieMonster.github.io

CSS
2
star
33

lisa-kitchen-demo

Example used for Test-Kitchen demo
PowerShell
2
star
34

wip

Stuff that doesn't have a home yet
PowerShell
1
star
35

zAppVeyor-Explore

PowerShell
1
star