Skip to content

Instantly share code, notes, and snippets.

@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 / Get-SpecialFolder.ps1
Last active September 25, 2018 04:25
Get-SpecialFolder: PowerShell function that retrieves special folder (known folders), i.e., folders with special meaning to the OS.
function Get-SpecialFolder {
<#
.SYNOPSIS
Gets special (known) folders.
.DESCRIPTION
Gets items representing special folders (directories), i.e.,
folders whose purpose is predefined by the operating system.
In a string context, each such item expands to the full, literal path it
@mklement0
mklement0 / New-CsvSampleData.ps1
Last active September 25, 2018 04:26
New-CsvSampleData: PowerShell function for automated creation of sample CSV data
function New-CsvSampleData {
<#
.SYNOPSIS
Generates CSV sample data.
.DESCRIPTION
Generates simple CSV sample data as either a single multiline string or
an array of lines.
For now, the data-row field values are simply constructed as:
@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 / Invoke-WithEnvironment.ps1
Created October 10, 2018 02:27
PowerShell script/function that invokes a command with a temporarily modified environment.
function Invoke-WithEnvironment {
<#
.SYNOPSIS
Invokes commands with a temporarily modified environment.
.DESCRIPTION
Modifies environment variables temporarily based on a hashtable of values,
invokes the specified script block, then restores the previous environment.
.PARAMETER Environment
@mklement0
mklement0 / Invoke-Life.ps1
Created October 23, 2018 14:33
PowerShell script that implements a terminal-based version of Conway's Game of Life (see https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
<#
.SYNOPSIS
A terminal-based implementation of Conway's Game of Life.
.DESCRIPTION
Conway's Game of Life is a zero-player game that simulates a cellular automaton.
See https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life for background.
The initial state can be seeded explicitly or, by default, randomly.
@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
@mklement0
mklement0 / Get-HelpFile.ps1
Last active April 3, 2019 16:21
Edition-agnostic PowerShell script/function for locating help-topic source files, optionally by part of their file name.
<#
NOTE:
It is BEST TO DOT-SOURCE (.) THIS SCRIPT, which defines a function of the same
name for later use.
While it is possible to invoke this script directly, its help can then only
be invoked with the -? switch, providing only terse help,
whereas dot-sourcing provides full Get-Help integration.
Similarly, only with dot-sourcing do you get tab completion.
@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 / Use-Culture.ps1
Created September 9, 2020 23:03
PowerShell script/function that executes a script block with a given culture and UI culture in effect
<#
NOTE:
It is BEST TO DOT-SOURCE (.) THIS SCRIPT, which defines a function of the same
name for later use.
While it is possible to invoke this script directly, its help can then only
be invoked with the -? switch, providing only terse help,
whereas dot-sourcing provides full Get-Help integration.
Similarly, only with dot-sourcing do you get tab completion.