Skip to content

Instantly share code, notes, and snippets.

@PanosGreg
PanosGreg / Sorting.ps1
Last active May 23, 2024 11:39
Different ways to sort objects
## Different ways to Sort
# ========================
# a) via Array class and the .Sort() method
# b) via LINQ and the OrderBy() method
# c) via the Sort-Object function
# d) via Comparer class for
# d1) List & SortedSet
@mklement0
mklement0 / Debug-String.ps1
Last active August 24, 2023 06:40
PowerShell function to visualize control characters and Unicode characters in strings
<#
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions)
License: MIT
Author: Michael Klement <[email protected]>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/7f2f1e13ac9c2afaf0a0906d08b392d1/raw/Debug-String.ps1 | iex
using module ActiveDirectory
using namespace System.Reflection
function Convert-ADFilter {
<#
.SYNOPSIS
Converts PowerShell-style filters used by the AD module into LDAP filters.
.DESCRIPTION
Convert-ADFilter uses the QueryParser from the AD module to convert PowerShell-style filters into LDAP
@JustinGrote
JustinGrote / ThrowUser.ps1
Last active January 24, 2025 10:28
A powershell throw alternative that uses the parent context for the stacktrace that is more user-friendly. Useful as a private function in powershell modules.
using namespace System.Management.Automation
function ThrowUser {
<#
.SYNOPSIS
Throws a terminating exception record that shows the cmdlet as the source of the error, rather than the inner "throw". Makes for more user friendly errors than simply using "throw"
.INPUTS
[String]
[Exception]
[Object]
.OUTPUTS
@fnky
fnky / ANSI.md
Last active June 29, 2025 22:49
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@mklement0
mklement0 / Time-Command.ps1
Last active December 18, 2024 07:42
PowerShell function that times the execution of one or more commands, averaged over a specifiable number of runs.
<#
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions)
License: MIT
Author: Michael Klement <[email protected]>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/9e1f13978620b09ab2d15da5535d1b27/raw/Time-Command.ps1 | iex
@pierrejoubert73
pierrejoubert73 / markdown-details-collapsible.md
Last active June 28, 2025 20:00
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux
@lalibi
lalibi / Set-WindowState.ps1
Last active April 11, 2025 09:14 — forked from Nora-Ballard/Set-WindowState.ps1
Hide, Show, Minimize, Maximize, etc window from Powershell.
function Set-WindowState {
<#
.SYNOPSIS
Set the state of a window.
.DESCRIPTION
Set the state of a window using the `ShowWindowAsync` function from `user32.dll`.
.PARAMETER InputObject
The process object(s) to set the state of. Can be piped from `Get-Process`.
@wpsmith
wpsmith / New-ErrorRecord.ps1
Created April 16, 2015 14:16
PowerShell: Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
<#
.Synopsis
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Description
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Parameter Exception
The Exception that will be associated with the ErrorRecord.