Skip to content

Instantly share code, notes, and snippets.

@peaeater
peaeater / restore.ps1
Created Dec 15, 2016
Powershell script to restore a SQL database from a backup file, with progress indicator.
View restore.ps1
<#
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 / text-mirror.ps1
Last active Jun 22, 2022
Create a text file mirror from PDFs, requires poppler
View text-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
.\text-mirror.ps1 -in C:\dev\abc\extract\extracted\pdfs\abc-pdfs-1.txt `
@peaeater
peaeater / tif2dzi.ps1
Created Jun 22, 2022
DZI Deep Zoom Images from TIFs, requires libvips (https://libvips.github.io/libvips/)
View tif2dzi.ps1
<#
1. Leaf
Given a text file of TIF/TIFF filenames, create DZI (Deep Zoom Image) tiles from TIFs
and create a mirror directory structure for DZI file outputs.
* Handles filenames with entry separators
* Ignores TIF older than its DZI mirror unless -force param is used
* Requires libvips (https://libvips.github.io/libvips/)
.\tif2dzi.ps1 -in c:\dev\abc\extract\extracted\tifs\abc-tifs-1.txt `
@peaeater
peaeater / tif2jpg.ps1
Last active Jun 22, 2022
Produces a JPG per TIF, requires imagemagick => http://www.imagemagick.org/
View tif2jpg.ps1
<#
1. Leaf
Given a text file of TIF/TIFF filenames, create JPGs from TIFs
and create a mirror directory structure for JPG file outputs.
* Handles filenames with entry separators
* Ignores TIF older than its JPG mirror unless -force param is used
* Requires imagemagick
.\tif2jpg.ps1 -in c:\dev\abc\extract\extracted\tifs\abc-tifs-1.txt `
View replace-server-in-cbs.ps1
<#
Peter Tyrrell, Andornot
Replaces old sql server name with new in textbase binary *.cbs file.
Note: Uses PowerShell Core syntax. See comments for Windows PowerShell.
Note: Server names of different lengths corrupt the file.
#>
param (
@peaeater
peaeater / cd2mp3.ps1
Last active May 4, 2022
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 / force-latest-tls.ps1
Created Dec 1, 2021
Tells .net to use strongest available TLS. Global setting - modifies registry keys.
View force-latest-tls.ps1
<#
Modifies regedit to tell all versions of .NET to use strongest available TLS. Global setting.
Requires admin privileges.
Peter Tyrrell
#>
# check for admin
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning ("You do not have admin privileges. Re-run this script as an administrator.")
@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)
@peaeater
peaeater / sftp-dir-to-remote.ps1
Created Oct 19, 2020
Powershell using WinSCP to sync directories over SFTP with file mask.
View sftp-dir-to-remote.ps1
<#
Sync a local to remote directory in SFTP mode
#>
param(
[Parameter(Mandatory = $false, Position = 0)]
[string]$logsrc = "",
[Parameter(Mandatory = $true, Position = 1)]
[string]$hostname,
[Parameter(Mandatory = $true, Position = 2)]
@peaeater
peaeater / Global.asax.cs
Created Sep 28, 2020
Force ImageResizer to authorize images larger than thumbnail based on user role in ASP.NET MVC
View Global.asax.cs
protected void Application_Start()
{
// various setup bits here...
Config.Current.Pipeline.AuthorizeImage +=
delegate (IHttpModule sender, HttpContext context, IUrlAuthorizationEventArgs e)
{
// only restrict ~/media
if (!e.VirtualPath.StartsWith(VirtualPathUtility.ToAbsolute("~/media")))
{