Skip to content

Instantly share code, notes, and snippets.

@peaeater
peaeater / helper.logging.ps1
Last active April 24, 2020 18:07
Log Helper writes to Event Log, console host or file depending on log source.
<#
Logging functions.
#>
function logError([string]$logsrc, [string]$msg) {
if ([String]::IsNullOrWhiteSpace($logsrc)) {
write-log -msg $msg -level "ERROR"
}
elseif (@(".txt", ".log").Contains([System.IO.Path]::GetExtension($logsrc)) -eq $true) {
write-log -msg $msg -level "ERROR" -file $logsrc
@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 / 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 / AppPoolResurrector.ps1
Last active July 30, 2018 00:28
Restarts named application pool if stopped, writes restart event to the Windows Application Event Log.
# restarts named app pool if stopped, writes restart event to the Application Event Log
# Peter Tyrrell, May 13 2013
param(
[string[]]$names = (,"ISAPI Webpublisher")
)
# If OS < Server 2008 R2, install Powershell snap-in for IIS and uncomment:
#Add-PSSnapin WebAdministration
@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 / 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"
)
@peaeater
peaeater / djvu2tif.ps1
Created November 29, 2013 18:06
Produce a TIF per page from the input DJVU file. The output name is simply the page number of the current page. Requires ddjvu => http://djvu.sourceforge.net/doc/man/ddjvu.html
# extract tif per page from djvu
# requires djvulibre
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0)]
[string]$in
)
process
{