Skip to content

Instantly share code, notes, and snippets.

@mklement0
mklement0 / ConvertTo-IntegerUnchecked.ps1
Last active Sep 10, 2022
PowerShell function that converts a given integer to another integer type unchecked, i.e. with overflow allowed.
View ConvertTo-IntegerUnchecked.ps1
<#
Prerequisites: Windows PowerShell v5.1 (possibly earlier; untested) or PowerShell (Core)
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and INSTANT DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/a700e598b615a1d432cc87e7291cdfec/raw/ConvertTo-IntegerUnchecked.ps1 | iex
View Benchmark_ParallelismInFileSystemEnumerations.ps1
#requires -Version 7
# Download and define function `Time-Command` on demand (will prompt).
# To be safe, inspect the source code at the specified URL first.
if (-not (Get-Command -ErrorAction Ignore Time-Command)) {
$gistUrl = 'https://gist.github.com/mklement0/9e1f13978620b09ab2d15da5535d1b27/raw/Time-Command.ps1'
if ((Read-Host "`n====`n OK to download and define benchmark function ``Time-Command```n from Gist ${gistUrl}?`n=====`n(y/n)?").Trim() -notin 'y', 'yes') { Write-Warning 'Aborted.'; exit 2 }
Invoke-RestMethod $gistUrl | Invoke-Expression 3>$null
if (-not ${function:Time-Command}) { exit 2 }
}
@mklement0
mklement0 / Add-NuGetType.ps1
Last active Mar 27, 2022
PowerShell function for experimenting with loading .NET assemblies from NuGet packages that are downloaded and cached on demand
View Add-NuGetType.ps1
<#
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions)
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/7436c9e4b2f73d7256498f959f0d5a7c/raw/Add-NuGetType.ps1 | iex
@mklement0
mklement0 / Show-Help.ps1
Last active Sep 12, 2022
Wrapper PowerShell function for Get-Help that shows help topics online by default and supports copying URLs of / Markdown links to the online help topics to the clipboard
View Show-Help.ps1
<#
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions)
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/880624fd665073bb439dfff5d71da886/raw/Show-Help.ps1 | iex
@mklement0
mklement0 / PSReadLineMetaInfoKeyHandler.ps1
Last active Apr 26, 2021
PowerShell sample code that demonstrates a PSReadLine key handler that display meta-information about the command being typed in real time.
View PSReadLineMetaInfoKeyHandler.ps1
<#
License: MIT
Author: Michael Klement <mklement0@gmail.com>
See https://stackoverflow.com/a/67266971/45375 for more information.
#>
# The printable characters to respond to.
@mklement0
mklement0 / Invoke-WithEncoding.ps1
Last active Oct 25, 2021
PowerShell function for invoking native (external) programs with a specified character encoding
View Invoke-WithEncoding.ps1
<#
Prerequisites: PowerShell v3+
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/ef57aea441ea8bd43387a7d7edfc6c19/raw/Invoke-WithEncoding.ps1 | iex
@mklement0
mklement0 / Debug-NativeInOutput.ps1
Last active Oct 17, 2021
PowerShell function for diagnosing character-encoding problems when communication with native (external) programs
View Debug-NativeInOutput.ps1
<#
Prerequisites: PowerShell v3+
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/eac1f18fbe0fc2798b214229b747e5dd/raw/Debug-NativeInOutput.ps1 | iex
@mklement0
mklement0 / Debug-String.ps1
Last active Apr 5, 2022
PowerShell function to visualize control characters and Unicode characters in strings
View Debug-String.ps1
<#
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions)
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/7f2f1e13ac9c2afaf0a0906d08b392d1/raw/Debug-String.ps1 | iex
@mklement0
mklement0 / Select-StringFormatted.ps1
Last active Apr 28, 2021
PowerShell function that wraps Select-String to make it search the formatted representations of its input objects.
View Select-StringFormatted.ps1
<#
Prerequisites: PowerShell v3+
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/46fea9e6e5ef1a3ceaf681c976cb68e3/raw/Select-StringFormatted.ps1 | iex
@mklement0
mklement0 / Out-HostColored.ps1
Last active Sep 10, 2022
PowerShell function that colors portions of the default host output that match given patterns.
View Out-HostColored.ps1
<#
Prerequisites: PowerShell version 2 or above.
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD, from PowerShell version 3 or above:
irm https://gist.github.com/mklement0/243ea8297e7db0e1c03a67ce4b1e765d/raw/Out-HostColored.ps1 | iex