Skip to content

Instantly share code, notes, and snippets.

@BroVic
Created June 19, 2020 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BroVic/19501f04867b1cdc736c55d72f05e1d3 to your computer and use it in GitHub Desktop.
Save BroVic/19501f04867b1cdc736c55d72f05e1d3 to your computer and use it in GitHub Desktop.
A PowerShell script for installing the PSSQLite Module
# install-pssqlite.ps1
# Copyright (c) 2018 Victor Ordu. All rights reserved.
# See LICENSE for details.
Write-Verbose "Checking for avaiablity of PSSQLite Module"
# Check if SQLite is (properly) installed
if(-not $ENV:Path.Contains('sqlite')) {
Write-Error "'sqlite3' does not exist or is not on system PATH."
}
# Install PSSQLite Module (if necessary)
if (-not (Get-Module -ListAvailable | Where-Object { $_.Name -eq "PSSQLite" } )) {
$ver = $PSVersionTable.PSVersion.Major
if (($ver -lt 5) -and ($ver -ge 3)) {
Add-Type -AssemblyName System.IO.Compression.Filesystem -ErrorAction Stop
# Download the archive
$url = 'https://github.com/RamblingCookieMonster/PSSQLite/zipball/master'
$dwnDir = "$home/Downloads"
if (-not (Test-Path $dwnDir)) {
New-Item -ItemType Directory $dwnDir
}
$sqlZip = Join-Path -Path $dwnDir -ChildPath "PSSQLite.zip"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Verbose "Downloading the PSSQLite Module... "
Invoke-WebRequest -Uri $url -OutFile $sqlZip | Write-Progress
# Unzip it to user's Module directory
$userModPath = $env:PSModulePath.split(';') | Where-Object { $_.Contains("Documents") }
if (-not (Test-Path $userModPath)) {
New-Item -ItemType Directory $userModPath
}
$Overwrite = $true
$files = [IO.Compression.Filesystem]::OpenRead($sqlZip).Entries
$files | ForEach-Object -Process {
$filepath = Join-Path -Path $userModPath -ChildPath $_
[IO.Compression.ZipFileExtensions]::ExtractToFile($_, $filepath, $Overwrite)
}
}
elseif ($ver -ge 5) {
Install-Module PSSQLite -Scope CurrentUser
}
else {
Write-Output "Automated installation not enabled for versions lower than 3.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment