Skip to content

Instantly share code, notes, and snippets.

@StartAutomating
StartAutomating / EventBasedServer.ps1
Last active August 8, 2025 17:43
Gist a small event-based HTTP server in PowerShell
$JobName = "http://localhost:$(Get-Random -Min 4200 -Max 42000)/"
$httpListener = [Net.HttpListener]::new()
$httpListener.Prefixes.Add($JobName)
$httpListener.Start()
Start-ThreadJob -ScriptBlock {
param($MainRunspace, $httpListener, $SourceIdentifier = 'http')
while ($httpListener.IsListening) {
$contextAsync = $httpListener.GetContextAsync()
while (-not ($contextAsync.IsCompleted -or $contextAsync.IsFaulted -or $contextAsync.IsCanceled)) {}
@JustinGrote
JustinGrote / Write-FunctionError.ps1
Last active February 28, 2023 21:57
Write an Error within a function in a nice way that displays the context of the function rather than the "Write-Error" context
using namespace System.Management.Automation
using namespace Microsoft.PowerShell.Commands
function Write-FunctionError {
<#
.SYNOPSIS
Writes an error within the context of the containing CmdletBinding() function. Makes errr displays prettier
#>
param(
[Parameter(Mandatory)][String]$Message,
[ValidateNotNullOrEmpty()][ErrorCategory]$Category = 'WriteError',
@inammathe
inammathe / Copy-OctopusVariableSet.ps1
Last active August 29, 2018 21:45
Copies from one Octopus Deploy project variables to another
Function Copy-OctopusVariableSet
{
<#
.SYNOPSIS
Copies from one Octopus Deploy project variables to another
.DESCRIPTION
Uses the Octopus rest api to get all variables from one project to replace all variables in another.
Super handy if you need to get a new project going with almost identical variables that don't yet exist in a project template or library set
.EXAMPLE
PS C:\> Copy-OctopusVariableSet `
@Jaykul
Jaykul / Manifest.psm1
Last active December 28, 2023 05:34
Update Module Version ... or anything else
function Update-Manifest {
#.Synopsis
# Update a PowerShell module manifest
#.Description
# By default Update-Manifest increments the ModuleVersion, but it can set any key in the Module Manifest, its PrivateData, or the PSData in PrivateData.
#
# NOTE: This cannot currently create new keys, or uncomment keys.
#.Example
# Update-Manifest .\Configuration.psd1
#
@ctigeek
ctigeek / Start-Sleep.ps1
Created March 23, 2016 14:44
Powershell sleep function, with progress bar.
function Start-Sleep($seconds) {
$doneDT = (Get-Date).AddSeconds($seconds)
while($doneDT -gt (Get-Date)) {
$secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds
$percent = ($seconds - $secondsLeft) / $seconds * 100
Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining $secondsLeft -PercentComplete $percent
[System.Threading.Thread]::Sleep(500)
}
Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining 0 -Completed
}
@urasandesu
urasandesu / Get-HelpByMarkdown.ps1
Last active August 5, 2023 04:12
This script converts PowerShell comment-based help to GitHub Flavored Markdown.
#
# File: Get-HelpByMarkdown.ps1
#
# Author: Akira Sugiura (urasandesu@gmail.com)
#
#
# Copyright (c) 2014 Akira Sugiura
#
# This software is MIT License.
#
@josheinstein
josheinstein / Dialogs.psd1
Last active February 4, 2020 02:58
A PowerShell module for showing common dialogs. (Currently only supports open and save file dialogs.)
@{
# MODULE
Description = "Common Dialogs Module"
ModuleVersion = '1.0'
GUID = '374EF8CD-AEC6-464C-92DA-290C662DA183'
# AUTHOR
Author = 'Josh Einstein'