Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Jaykul / About CommandNotFoundAction.md
Last active June 26, 2024 12:23
Helpfully handling Command Not Found in PowerShell

Helpfully handling Command Not Found in PowerShell

About CommandNotFoundAction

In PowerShell there is a callback ("Action") that is called when a command lookup fails through normal means. The purpose of this callback is to allow you to add your own command-resolution, and there are a lot of community hacks out there already:

Community Implementations

  • You could add support for new command types, like
using namespace System.Collections.Generic; using namespace System.Text
Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
using System.Text;
public class WindowTools
{
public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);
@JustinGrote
JustinGrote / ModuleFast.ps1
Last active August 17, 2024 11:42
Bootstrap Script for a High Performance Module Installer
using namespace System.Net.Http
#requires -version 7.2
# This is the bootstrap script for Modules
[CmdletBinding(PositionalBinding = $false)]
param (
#Specify a specific release to use, otherwise 'latest' is used
[string]$Release = 'latest',
#Specify the user
[string]$User = 'JustinGrote',
#Specify the repo
@danieldogeanu
danieldogeanu / MakePowerShellRememberSSHPassphrase.md
Last active May 2, 2025 14:52
How to make Powershell remember the SSH key passphrase.

You should not use the Open SSH client that comes with Git for Windows. Instead, Windows 10 has its own implementation of Open SSH that is integrated with the system. To achieve this:

  1. Start the ssh-agent from Windows Services:
  • Type Services in the Start Menu or Win+R and then type services.msc to launch the Services window;
  • Find the OpenSSH Authentication Agent in the list and double click on it;
  • In the OpenSSH Authentication Agent Properties window that appears, choose Automatic from the Startup type: dropdown and click Start from Service status:. Make sure it now says Service status: Running.
  1. Configure Git to use the Windows 10 implementation of OpenSSH by issuing the following command in Powershell:
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
@brettmillerb
brettmillerb / profile.ps1
Last active January 18, 2022 00:46
Mac Pwsh Profile
Import-Module -Name Toolbox
Import-Module -Name Microsoft.PowerShell.UnixCompleters
Import-Module -Name Terminal-Icons
function BackOne {
Set-Location ..
}
function BackTwo {
Set-Location ../..
}
@JustinGrote
JustinGrote / AutoMock.ps1
Last active November 2, 2021 21:16
AutoMock: Record Powershell Command Output to Replay in Pester Tests Offline
#requires -module Indented.StubCommand
function Enable-AutoMockRecord ([Switch]$Append) {
$env:AUTOMOCK_RECORD = $true
if ($Append) {$env:AUTOMOCK_APPEND = $true}
}
function Disable-AutoMockRecord {
Remove-Item env:AUTOMOCK_RECORD -ErrorAction SilentlyContinue
Remove-Item env:AUTOMOCK_APPEND -ErrorAction SilentlyContinue
}
@Jaykul
Jaykul / Get-ColorMode.ps1
Last active March 27, 2025 05:18
Virtual terminal queries (DECRQSS) return values as INPUT but allow us to test support for syntax
function Get-ColorMode {
<#
.SYNOPSIS
Tests for FullColor (RGB) mode and X11/XTerm (XColor) modes by writing SGR and verifying it with a DECRQSS
Returns "Uknown" if there's no DECRQSS support, or "FullColor" and/or "XColor" otherwise
.NOTES
See the XTerm FAQ for details on why some terminals use ; (to be compatible with a mistake made by XTerm)
https://invisible-island.net/xterm/xterm.faq.html#color_by_number
See the ISO-8613-6 standard for details on the ODA color modes
@jborean93
jborean93 / Start-WindowsTerminal.ps1
Created May 22, 2020 21:25
Starts Windows Terminal as the current user, another user, and optionally elevated.
# Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Start-WindowsTerminal {
<#
.SYNOPSIS
Start Windows Terminal from PowerShell.
.DESCRIPTION
Start Windows Terminal from PowerShell. This can be done as the current user, another user, and optionally
@ninmonkey
ninmonkey / Powershell Performance testing -- adding to arrays is slow.md
Last active July 29, 2022 01:44
Powershell Performance -- Adding elements to arrays is **very** slow

Powershell Performance: Adding to arrays is slow

powershell array performance results

A common pattern in many languages adds an element to an array or list

elements = []
for x in range(10000):
 elements.append(x)
using namespace System.Management.Automation
# Use of StopUpstreamCommandsException is obviously not supported. Subject to breaking at any time.
function Select-FirstObject {
[Alias('first', 'top')]
[CmdletBinding(PositionalBinding = $false)]
param(
[Parameter(ValueFromPipeline)]
[psobject] $InputObject,