Skip to content

Instantly share code, notes, and snippets.

@mklement0
mklement0 / New-EncodingTestFiles.ps1
Last active August 16, 2022 08:18
PowerShell scripts for creating and reading test files with the standard Unicode character encoding schemes and default encodings.
<#
.SYNOPSIS
Creates test text-based files with various character encodings.
.DESCRIPTION
Creates text-based test files using
* all 5 byte order-marked Unicode character encoding schemes,
both with and without BOM (Unicode signature)
* default encodings,
with the the platform's default encoding, [System.Text.Encoding]::Default
@mklement0
mklement0 / Get-DotNetVersion.ps1
Last active September 25, 2018 04:33
PowerShell v6+ script for getting version information about a .NET Core installation in general or a specific .NET Core project.
function Get-DotNetCoreVersion {
<#
.SYNOPSIS
Gets version information about a .NET Core installation or project.
.DESCRIPTION
Gets version information about the globally installed .NET Core components
or a specific project.
Note: Requires PSv6+, due to use of type
@mklement0
mklement0 / Out-FileUtf8NoBom.ps1
Last active December 23, 2022 15:30
PowerShell function that emulates Out-File for creating UTF-8-encoded files *without a BOM* (byte-order mark).
<#
Prerequisites: PowerShell version 3 or above.
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/8689b9b5123a9ba11df7214f82a673be/raw/Out-FileUtf8NoBom.ps1 | iex
The above directly defines the function below in your session and offers guidance for making it available in future
@mklement0
mklement0 / Select-StringAll.ps1
Last active April 24, 2021 13:19
PowerShell function that wraps the Select-String cmdlet with conjunctive matching (ALL search patterns must match).
<#
Prerequisites: PowerShell v3+
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and INSTANT DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/356acffc2521fdd338ef9d6daf41ef07/raw/Select-StringAll.ps1 | iex
@mklement0
mklement0 / fanout
Last active April 2, 2018 20:07
fanout - a Unix utility for sending stdin input to multiple target commands
#!/usr/bin/env bash
# fanout utility - send stdin input to multiple target commands.
#
# Copyright (c) 2017 Michael Klement, released under the [MIT license](http://opensource.org/licenses/MIT).
#
# Aside from requiring Bash 3+, this utility should be portable:
# It uses only POSIX-compliant utilities with POSIX-compliant options.
#
# Invoke with --help for help.
@mklement0
mklement0 / wrapper.cmd
Last active December 6, 2022 01:35
wrapper.cmd - a wrapper batch-file template for executing embedded PowerShell and/or VBScript/JScript code
@echo off
setLocal enableDelayedExpansion
:: === ADAPTING THIS TEMPLATE (for help, see bottom or invoke with "help") ===
:: * Step 1 of 3: CLONE THIS BATCH FILE and give it a name of your choice.
:: * Step 2 of 3: Set the TARGET LANGUAGE on the next line.
:: One of: "ps1" "vbs" "js" (PowerShell, VBScript, JScript)
:: OR: "all" (runs ALL embedded snippets, in sequence)
:: NOTE: To add support for a new language, search for "NEW LANGUAGE"
:: below and follow the instructions there.
set "WRAPPER_LANG=ps1"
@mklement0
mklement0 / Test-WinCredential.ps1
Last active April 18, 2024 01:33
Test-WinCredential: PowerShell function for validating Windows domain / local user credentials.
<#
Prerequisites: Windows PowerShell 5.1, PowerShell (Core) (v6+) - MAY work in earlier versions
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and INSTANT DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/83e8e6a2b39ecec7b0a14a8e631769ce/raw/Test-WinCredential.ps1 | iex
@mklement0
mklement0 / Time-Command.ps1
Last active November 19, 2023 17:08
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 <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/9e1f13978620b09ab2d15da5535d1b27/raw/Time-Command.ps1 | iex
@mklement0
mklement0 / Get-CmdletMinPsVersion.ps1
Last active November 22, 2019 15:57
Get-CmdletMinPsVersion: PowerShell function for determining the minimum PowerShell version required to run given standard cmdlets.
function Get-MinPsVersionForCmdlet {
<#
.SYNOPSIS
Determines the minimum PowerShell version required for a given standard cmdlet.
.DESCRIPTION
NOTE:
* v3 or higher is required to run this function.
* Only cmdlets with help topics defined in the GitHub
PowerShell-documentation repository at
@mklement0
mklement0 / Get-OpenFiles.ps1
Last active April 1, 2019 18:52
Get-OpenFiles: PowerShell function for locating open files in a given directory [subtree]
function Get-OpenFiles {
<#
.SYNOPSIS
Finds open files.
.DESCRIPTION
Finds files currently being held open by any process and reports them as
[System.IO.FileInfo] instances, as Get-ChildItem would.
In fact, this function supports all parameters that Get-ChildItem does and