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 / Set-Permissions.ps1
Created August 25, 2021 13:12
Set file or directory permissions easily with a PowerShell cmdlet
<#
.SYNOPSIS
Set file system permissions for a given path and user
.EXAMPLE
.\Set-Permissions.ps1 -Path C:\foo -User SomeUser -Rights FullControl
Allow SomeUser to have full control over C:\foo
.EXAMPLE
@pcrockett-pathway
pcrockett-pathway / Send-Discord.ps1
Created July 27, 2021 14:09
Invoke a Discord Webhook from PowerShell
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string]$WebhookUrl,
[Parameter(Mandatory=$True)]
[string]$Content
)
$ErrorActionPreference = "Stop"
@pcrockett-pathway
pcrockett-pathway / Get-SecureRandom.ps1
Created July 15, 2021 14:30
Generate secure pseudorandom data either as a byte array or base64 string
<#
.SYNOPSIS
Generate secure pseudorandom data either as a byte array or base64 string
.PARAMETER Bytes
Number of bytes to generate. Defaults to 16.
.PARAMETER Base64
Output bytes in base64-encoded string
@pcrockett-pathway
pcrockett-pathway / NotifyCronitor.bat
Last active March 26, 2020 16:26
Monitor a Duplicati backup with Cronitor
@echo off
powershell.exe -Command %~dp0CronitorNotify.ps1 -MonitorCode MONITOR_CODE_HERE
@pcrockett-pathway
pcrockett-pathway / rebase-notes.md
Created March 20, 2020 14:50
Personal rebase summary

To move a range of commits in Git so they are based on a different commit:

git rebase --onto new-base current-base latest-commit
  • new-base: This is the commit you want to move the range to. This commit will be the new parent of the commits you're moving.
  • current-base: This is the commit that your range is currently based on. It is not the first commit in the range, but the parent of the first commit.
  • latest-commit: This is the tip, the most recent commit in your commit range.
@pcrockett-pathway
pcrockett-pathway / Disable-BingSearch.ps1
Created February 6, 2020 09:40
Disable Bing search in the Windows 10 Start Menu
<#
.SYNOPSIS
Disable Bing search in the Windows 10 Start Menu
.DESCRIPTION
Inspired by https://www.windowscentral.com/how-fix-taskbar-search-not-working-windows-10
#>
[CmdletBinding()]
param()
@pcrockett-pathway
pcrockett-pathway / DirectoryLockdown.ps1
Created February 4, 2020 14:02
Create a directory and lock down permissions so only the current user has access to it
New-Item -ItemType Directory $configDir | Out-Null
$acl = Get-Acl $configDir
$acl.SetAccessRuleProtection($True, $False) # Clear all access rules, disable permission inheritance
$currentUser = [Security.Principal.NTAccount]::new($env:USERNAME)
$acl.SetOwner($currentUser)
$accessRule = [Security.AccessControl.FileSystemAccessRule]::new($currentUser, "FullControl", "Allow")
$acl.SetAccessRule($accessRule)
Set-Acl -Path $configDir -AclObject $acl
@pcrockett-pathway
pcrockett-pathway / MakePairs.cs
Created January 23, 2020 14:46
LINQ-like extension method for iterating over pairs of items
/// <summary>
/// Pairs adjacent items in an IEnumerable and executes a selector delegate on the two items together.
/// Returns an IEnumerable that contains one fewer item than the original.
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="source"></param>
/// <param name="pairFunc"></param>
/// <returns></returns>
public static IEnumerable<TResult> MakePairs<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TSource, TResult> pairFunc)
@pcrockett-pathway
pcrockett-pathway / New-PSConsole.ps1
Last active December 20, 2019 09:59
Run commands or start interactive PowerShell sessions as any user, elevated or not
[CmdletBinding()]
param(
[Parameter()]
[string]$UserName,
[Parameter()]
[string]$Command,
[Parameter()]
[string]$WorkingDirectory,
@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