

PowerShell is a cross-platform (Windows, Linux, and macOS) automation tool and configuration framework optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. PowerShell includes a command-line shell, object-oriented scripting language, and a set of tools for executing scripts/cmdlets and managing modules.
Compare contents of file with SQLite database table
Hi All,
Trying to do figure out some automation using PowerShell.
I've got a script to check a website for contents and export to a text file, what I'm trying to achieve in the next step in the process is to compare the contents of the text file to a SQLite database that gets downloaded as part of a separate part of the script.
I've already imported the SQLite module and can access the database, read and write to it via PowerShell but I'm not entirely sure how to enable PowerShell to:
-
Read the contents of the .txt file
-
Compare the contents with a specific table in the SQLite database
I'm relatively new to this and only actually giving this a go because I'm off work for a few weeks, but is it even possible?
Perhaps exporting the contents of the SQLite query to a text file and then comparing two text files together is an easier approach?
There are several ways to do this, but it depends on the data structures you want to compare. Look into populating PSCustomObjects, or using Data Tables. For complex structures the latter would probably be preferable. The main thing is to make sure you're comparing apples to apples.
The question is, what is your definition of "equality" in this scenario?
More specifically,
-
Do data types matter?
-
What about text vs. numeric - is "1" supposed to be equal to 1?
Each SQL flavor defines its own data types, which don't necessarily match PowerShell's (or .NET's) data types, so if data types are supposed to be part of the equation, you'll have to implement some kind of algorithm that maps those.
For example SQLite's INTEGER data type consists of 7 different types of signed integers, so regarding a comparison, how would you want to handle that?
Or let's look at SQLite's TEXT data type - it's a text string that's stored using the database's encoding, so as soon as characters outside of codepage 437 come into play, you'd have to take the encoding into consideration when comparing values.
If a simple string comparison is sufficient, I'd recommend to export the SQL data to a supported text-based data format (I'd favor JSON or XML over CSV), and conduct comparisons on the exported data.