Skip to content

Instantly share code, notes, and snippets.

@peaeater
peaeater / sitemap.ps1
Created May 30, 2018
Creates sitemap index with attendant sitemaps from a Solr query.
View sitemap.ps1
<#
Create sitemap index with attendant sitemaps from a Solr query.
A new sitemap is created every 50,000 rows.
#>
param (
[string]$ChangeFrequency = "weekly",
[string]$IndexBaseUrl = "http://andi.andornot.com/",
[string]$Logsrc = "Andi Solr Update",
[string]$OutDir = ".\",
@peaeater
peaeater / optimize-pdf.ps1
Created May 25, 2018
Downsamples PDFs with ghostscript.
View optimize-pdf.ps1
<#
Downsample PDF and convert to gray if necessary.
Requires Ghostscript (gswin64c).
#>
param (
[string]$indir,
[string]$outdir = $indir,
[string]$gs = "gswin64c",
[string]$dpi = "150"
@peaeater
peaeater / logger.ps1
Created Mar 26, 2018 — forked from barsv/logger.ps1
Logging in powershell with log rotation
View logger.ps1
# all logging settins are here on top
$logFile = "log-$(gc env:computername).log"
$logLevel = "DEBUG" # ("DEBUG","INFO","WARN","ERROR","FATAL")
$logSize = 1mb # 30kb
$logCount = 10
# end of settings
function Write-Log-Line ($line) {
Add-Content $logFile -Value $Line
Write-Host $Line
@peaeater
peaeater / cd2mp3.ps1
Last active Mar 7, 2018
Powershell script that uses VLC to rip a CD audio track.
View cd2mp3.ps1
<#
Rip Audio CD to mp3 files with VLC.
#>
param (
[string]$vlc = "c:\program files\videolan\vlc\vlc.exe",
[string]$cddrive = "E:",
[int]$track = 0
)
@peaeater
peaeater / rip-cd.bat
Created Mar 7, 2018
Windows batch file that uses VLC to rip an audio CD
View rip-cd.bat
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
SET /a x=0
FOR /R E:\ %%G IN (*.cda) DO (CALL :SUB_VLC "%%G")
GOTO :eof
:SUB_VLC
@peaeater
peaeater / prune_elmah.ps1
Created Oct 31, 2017
Delete ELMAH_Error table rows from Andi db earlier than today - x days.
View prune_elmah.ps1
param (
[string]$server,
[string]$dbname,
[int]$daysToKeep,
[Parameter(Mandatory=$false)]
[string]$logsrc = "Andi Solr Update"
)
function logError([string]$logsrc, [string]$msg) {
# write error msg to Application EventLog
@peaeater
peaeater / prune_cart.ps1
Created Oct 31, 2017
Delete empty CartInstance table rows from Andi db earlier than today - x days.
View prune_cart.ps1
param (
[Parameter(Mandatory=$true)]
[string]$server,
[Parameter(Mandatory=$true)]
[string]$dbname,
[Parameter(Mandatory=$true)]
[int]$daysToKeep,
[Parameter(Mandatory=$false)]
[string]$logsrc = "Andi Solr Update"
)
@peaeater
peaeater / pdf2text-mirror.ps1
Created Jun 22, 2017
Given a file with PDF file paths or a directory containing PDFs, the script creates a text file mirror. Poppler is a dependency. Writes log events to Windows Application Log.
View pdf2text-mirror.ps1
<#
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
.\main.ps1 -in C:\dev\abc\extract\extracted\pdfs\db-pdfs-1.txt -pathprefix C:\dev\abc\raw\documents\publications -outdir C:\dev\abc\raw\documents\publications\test-out -poppler C:\utils\poppler-0.51\bin\pdftotext.exe
@peaeater
peaeater / portscan.ps1
Created May 17, 2017
Scans to see if an IP is listening on a given port.
View portscan.ps1
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 Apr 11, 2017
Creates new wildcard self-signed SSL certificate for development purposes. Needs PowerShell admin.
View self-signed-cert.ps1
# 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)
You can’t perform that action at this time.