A while back, I wrote about how I use SQLite to do, among other things, some database modeling. Typically, I will write all my table creation scripts in a single SQL file and then run that script at the command line like so:

C:\sqlite-tools-win32-x86-3300100\sqlite3.exe orders.db < orders_db.sql

This approach works great if you run your command in the Windows command shell or even in Linux, but will it work in PowerShell?

The answer is: No. PowerShell uses the “<” sign differently than the other two shells and won’t honor that command.

Both the Windows shell and Linux treat that “less than” sign as an “input redirection” instruction. You are redirecting your input, the SQL file, into the database you’re generating with the sqlite3 command utility.

So, in PowerShell, how might we accomplish this same sort of input redirection? One answer is to use PowerShell’s Get-Content cmdlet (using its alias “cat”) and pipe the content of the SQL script into the sqlite3 utility:

cat orders_db.sql | & C:\sqlite-tools-win32-x86-3300100\sqlite3.exe orders.db

Note that I’m using the ampersand operator as a “call operator” to launch the sqlite3 utility.

So, now you know how to use SQLite to load scripts in three different command shells!