Skip to content

Instantly share code, notes, and snippets.

View pcrockett-pathway's full-sized avatar

Philip Crockett pcrockett-pathway

View GitHub Profile
@pcrockett-pathway
pcrockett-pathway / Get-FileEncoding.ps1
Last active April 10, 2019 14:23
Get the encoding for a file
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True)]
[string]$Path
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 5.0
$Path = (Resolve-Path $Path).ProviderPath
@pcrockett-pathway
pcrockett-pathway / Copy-ToPeerRepos.ps1
Last active November 9, 2022 14:23
File encoding pre-commit hook. Just clone this Gist next to all your other repos and run Copy-ToPeerRepos.ps1
<#
.SYNOPSIS
Clone this repo alongside all your other code repos. Then run this script.
It will automatically copy the pre-commit hook scripts to your other repos.
#>
[CmdletBinding()]
param()
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 5.0
@pcrockett-pathway
pcrockett-pathway / Get-ClipboardHash.ps1
Last active November 26, 2018 09:25
Hashes the contents of your clipboard
[CmdletBinding()]
param(
[Parameter()]
[string]$Algorithm = "SHA1",
[Parameter()]
[Text.Encoding]$Encoding = [Text.Encoding]::UTF8
)
$ErrorActionPreference = "Stop"
$ErrorActionPreference = "Stop"
<#
.SYNOPSIS
Will reset your colors to the scheme found in $PROFILE
.DESCRIPTION
Useful for when programs mess up your favorite console colors. WARNING:
Will clear your screen.
@pcrockett-pathway
pcrockett-pathway / Reset-PrintSpool.ps1
Created February 18, 2019 10:43
Reset print spool service when your printer queue gets stuck
#Requires -RunAsAdministrator
[CmdletBinding()]
param()
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 5.0
# From https://help.logmein.com/articles/en_US/FAQ/How-do-I-clear-the-print-queue-if-a-document-is-stuck-en1
Stop-Service Spooler
@pcrockett-pathway
pcrockett-pathway / Disable-IeHsts.ps1
Created March 5, 2019 12:35
Example of editing the registry in PowerShell
#Requires -RunAsAdministrator
[CmdletBinding()]
param()
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 5.0
# Not fully tested. Before you try this, try clearing IE's history and
# temporary files. EVERYTHING. That will probably do it for you.
@pcrockett-pathway
pcrockett-pathway / Start-InfiniteLoop.ps1
Created May 9, 2019 08:10
Example of a PowerShell loop that a user can "escape" with a keystroke
[CmdletBinding()]
param(
[Parameter()]
[int]$PollFrequencySeconds = 2
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 5.0
$stopKey = "Q"
@pcrockett-pathway
pcrockett-pathway / Install-SyncthingService.ps1
Last active May 21, 2025 12:37
Install Syncthing as a service using NSSM
<#
.SYNOPSIS
Installs Syncthing as a Windows service
.DESCRIPTION
Uses NSSM (Non-Sucking Service Manager) to set up Syncthing as a Windows
service. Requires both Syncthing and NSSM to already be installed. nssm.exe
must be available via the PATH environment variable.
.PARAMETER InstallDir
@pcrockett-pathway
pcrockett-pathway / Elevate.ps1
Last active June 13, 2019 12:34
Self-elevating PowerShell script
[CmdletBinding()]
param()
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 5.0
$currentId = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal]$currentId
$adminRole = [Security.Principal.WindowsBuiltInRole]"Administrator"
if (!$principal.IsInRole($adminRole)) {
@pcrockett-pathway
pcrockett-pathway / Receive-PatchBay.ps1
Last active November 28, 2019 10:53
patchbay.pub scripts (see https://patchbay.pub/)
<#
.SYNOPSIS
Receive PGP-encrypted messages from patchbay.pub
.PARAMETER MyId
Your personal PGP key fingerprint
.PARAMETER PubSub
"Publish / Subscribe" mode: Use this switch if multiple subscribers (you
and perhaps other people) will all get the same messages from the