Skip to content

Instantly share code, notes, and snippets.

@peaeater
peaeater / text-mirror.ps1
Last active June 22, 2022 18:45
Create a text file mirror from PDFs, requires poppler
<#
1. Leaf
Given a text file of PDF filenames, extract content from PDFs recursively
and create mirror directory structure for text file outputs.
* Handles filenames with entry separators.
* Ignores PDF older than its text file mirror unless -force param is used.
* Requires poppler pdftotext.exe
.\text-mirror.ps1 -in C:\dev\abc\extract\extracted\pdfs\abc-pdfs-1.txt `
@peaeater
peaeater / portscan.ps1
Created May 17, 2017 23:10
Scans to see if an IP is listening on a given port.
param (
[int]$port,
[string]$ip
)
if (Test-Connection -BufferSize 32 -Count 1 -Quiet -ComputerName $ip) {
$socket = new-object System.Net.Sockets.TcpClient($ip, $port)
if ($socket.Connected) {
write-host "$ip is listening on port $port"
@peaeater
peaeater / self-signed-cert.ps1
Created April 11, 2017 23:40
Creates new wildcard self-signed SSL certificate for development purposes. Needs PowerShell admin.
# Creates new self-signed certificate for testing purposes
new-selfsignedcertificate -dnsname "*.domain.local" -friendlyname "*.domain.local Development Certificate" -certstorelocation "cert:\LocalMachine\My" -notafter (get-date).AddYears(100)
@peaeater
peaeater / file2folder.ps1
Created January 5, 2017 17:06
Create web-safe folder from portion of filename taken by supplied regex and move file into it.
<#
For each file:
1. take filename or portion of it,
2. create web-safe folder from template and filename match,
3. move file into new folder.
e.g. -format "arnpriorbylaw{0}" -take "(?m)(?i)\s*by-law\s*-\s*(\d{4}A*-\d{2})\s*-\s*.+$" => 'arnpriorbylaw1234-00'
#>
param(
@peaeater
peaeater / restore.ps1
Created December 15, 2016 19:06
Powershell script to restore a SQL database from a backup file, with progress indicator.
<#
sqlps dependency
If module sqlps does not exist, install from:
Microsoft SQL Server 2016 Feature Pack (https://www.microsoft.com/en-us/download/details.aspx?id=52676)
- SQLSysClrTypes.msi
- SharedManagementObjects.msi
- PowershellTools.msi
#>
param(
@peaeater
peaeater / script-table.ps1
Last active October 31, 2016 22:39
Generates schema and data for a given SQL Server table to file.
<#
Generates a CREATE/INSERT script for a given SQL Server db table (e.g. Localizations)
Peter Tyrrell, Andornot, www.andornot.com
sqlps dependency
If module sqlps does not exist, install from:
Microsoft SQL Server 2016 Feature Pack (https://www.microsoft.com/en-us/download/details.aspx?id=52676)
- SQLSysClrTypes.msi
- SharedManagementObjects.msi
- PowershellTools.msi
@peaeater
peaeater / clean-xml.ps1
Created October 26, 2016 18:12
Purges all illegal characters from XML files in provided folder. Recursive.
<#
Purges illegal XML characters from XML files in provided folder (and its subfolders).
Encodes out file as UTF8 without BOM.
Peter Tyrrell, Andornot
#>
param (
[string]$indir
)
@peaeater
peaeater / unzip.ps1
Created October 24, 2016 21:40
Picks up zip files in a given folder and extracts the contents to a destination folder.
<#
Picks up zip files in a given folder and extracts the contents to a destination folder.
Peter Tyrrell, Andornot
#>
param(
[Parameter(Mandatory=$true,Position=0)]
[string]$in,
[Parameter(Mandatory=$false,Position=1)]
[string]$out = ".",
@peaeater
peaeater / backup.ps1
Last active November 2, 2018 07:46
Backs up Inmagic textbases, both SQL Server db and textbase files. Logs most recent backup to a file.
<#
Backs up Inmagic textbases, both SQL Server db and relevant textbase files.
Peter Tyrrell, Andornot, www.andornot.com
sqlps dependency
If module sqlps does not exist, install from:
Microsoft SQL Server 2016 Feature Pack (https://www.microsoft.com/en-us/download/details.aspx?id=52676)
- SQLSysClrTypes.msi
- SharedManagementObjects.msi
- PowershellTools.msi
@peaeater
peaeater / dbt4sql-query.sql
Created August 22, 2016 20:42
Query to flatten records in an Inmagic DBTEXT for SQL internal database.
USE [name-of-db]
go
declare @cols AS NVARCHAR(MAX)
, @query AS NVARCHAR(MAX)
, @dechunkedRecords AS NVARCHAR(MAX)
, @where AS NVARCHAR(MAX);
set @where = ''
/*set @where = 'where _RecordID in (