Skip to content

Instantly share code, notes, and snippets.

@peaeater
peaeater / helper.logging.ps1
Last active January 9, 2025 18:30
Log Helper writes to console host or file depending on log source. Rotates logs. On Windows can write errors to Event Log.
param (
[Parameter(Mandatory = $false)]
[string]$LogSource = "",
[Parameter(Mandatory = $false)]
[string]$ErrorsToWinLogSource,
[string]$dateFormat = "yyyy-MM-dd HH:mm:ss"
)
<#
@peaeater
peaeater / zipline.ps1
Last active June 22, 2020 19:55
Zip textbases with System.IO.Compression
<#
Zip up textbase files in preparation for FTP sync to Andornot.
Peter Tyrrell, [email protected]
-textbases c:\path\to\accessions.tba, c:\path\to\descriptions.tba
-out c:\path\to\destination
#>
param (
[string[]] $textbases,
@peaeater
peaeater / archive-project.ps1
Created October 31, 2019 15:22
Archive an Andi project
param (
[Parameter(Mandatory = $true)]
[string]$in,
[string]$out = "d:\dev-archive"
)
$extract_output_dir = "$in\extract\extracted\output\*"
remove-item $extract_output_dir -Recurse
Write-Host "Removed $extract_output_dir"
@peaeater
peaeater / sitemap.ps1
Created May 30, 2018 16:23
Creates sitemap index with attendant sitemaps from a Solr query.
<#
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 17:47
Downsamples PDFs with ghostscript.
<#
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 March 26, 2018 20:41 — forked from barsv/logger.ps1
Logging in powershell with log rotation
# 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 December 14, 2024 13:04
Powershell script that uses VLC to rip a CD audio track.
<#
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 March 7, 2018 15:51
Windows batch file that uses VLC to rip an audio CD
@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 October 31, 2017 15:51
Delete ELMAH_Error table rows from Andi db earlier than today - x days.
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 October 31, 2017 15:47
Delete empty CartInstance table rows from Andi db earlier than today - x days.
param (
[Parameter(Mandatory=$true)]
[string]$server,
[Parameter(Mandatory=$true)]
[string]$dbname,
[Parameter(Mandatory=$true)]
[int]$daysToKeep,
[Parameter(Mandatory=$false)]
[string]$logsrc = "Andi Solr Update"
)