Skip to content

Instantly share code, notes, and snippets.

View aldrichtr's full-sized avatar

Tim Aldrich aldrichtr

View GitHub Profile
@aldrichtr
aldrichtr / ANSI.md
Created May 6, 2022 16:42 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
--------------------------------------------
Version: 1.45.1
Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a
Date: 2020-05-14T08:33:47.663Z
Electron: 7.2.4
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.5.0
-------------------------------------------
@aldrichtr
aldrichtr / mondayExample.ps1
Created July 22, 2022 16:12 — forked from yuhgto/mondayExample.ps1
monday.com Powershell API Example
# This example will update a date, person and text column for all items on a board
# It will show you how to query the API (read data) and mutate column values for each of the returned items.
# set URL and headers for API calls
$url = "https://api.monday.com/v2/"
$hdr = @{}
$hdr.Add("Authorization" , "YOUR_API_KEY_HERE")
$hdr.Add("Content-Type","application/json")
# set board ID
@aldrichtr
aldrichtr / Get-ParamBlock.ps1
Created September 21, 2022 21:03 — forked from JustinGrote/Get-ParamBlock.ps1
Get a hashtable of the parameters in your param block, useful for splatting.
using namespace system.collections.generic
function Get-ParamBlock ([String[]]$Name) {
[hashset[string]]$params = $PSCmdlet.MyInvocation.MyCommand.Parameters.Keys
$params.ExceptWith([string[]]([PSCmdlet]::CommonParameters + [PSCmdlet]::OptionalCommonParameters))
$result = @{}
if ($Name) {$params = $params -in $Name}
foreach ($name in $params) {
$result.$name = $PSCmdlet.GetVariableValue($name)
}
return $result
@aldrichtr
aldrichtr / Write-FunctionError.ps1
Created September 21, 2022 21:04 — forked from JustinGrote/Write-FunctionError.ps1
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',
@aldrichtr
aldrichtr / Receive-Task.ps1
Created September 21, 2022 21:05 — forked from JustinGrote/Receive-Task.ps1
"Await" one or more tasks in PowerShell in a cancellable manner (e.g. ctrl-c still works)
using namespace System.Threading.Tasks
using namespace System.Collections.Generic
filter Receive-Task {
#Wait on one or more tasks in a cancellable manner
[CmdletBinding()]
param(
[parameter(Mandatory, ValueFromPipeline)][Task]$Task,
#How long to wait before checking for a cancellation in milliseconds
[int]$WaitInterval = 500
)
@aldrichtr
aldrichtr / PSScriptAnalyzer-Git-Hook.md
Created September 21, 2022 21:08 — forked from dbrennand/PSScriptAnalyzer-Git-Hook.md
PowerShell 7 Pre Commit Hook using PSScriptAnalyzer

Summary

A PowerShell 7 pre commit hook to lint your PowerShell code using the PSScriptAnalyzer module.

Prerequisites

  1. PowerShell 7
  2. Git
  3. PSScriptAnalyzer module
# Add a domain user to a remote server local group, if your current user has admin over the remote machine
powershell -c ([ADSI]'WinNT://SERVER/Administrators,group').add('WinNT://DOMAIN/USER,user')
# Get all local groups on a remote server
powershell -c "([ADSI]'WinNT://SERVER,computer').psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach { ($_.name)[0]}"
# Find members of the local Administrators group on a remote server
powershell -c "$([ADSI]'WinNT://SERVER/Administrators,group').psbase.Invoke('Members') | foreach { $_.GetType().InvokeMember('ADspath', 'GetProperty', $null, $_, $null).Replace('WinNT://', '') }"
# Enable the local Administrator account on a remote server

Versioning Software

We need our software builds to label the software with a version number.

We want each build to produce a label that is unique enough that we can track a binary back to it's build and the commit it was based on.

We want to follow "Semantic Versioning" because our industry as a whole has decided it's useful.

We want the version number to be predictable, so that (as developers) we know what version of the software we're working on.

@aldrichtr
aldrichtr / Format-Relative.ps1
Created November 5, 2022 03:53 — forked from daephx/Format-Relative.ps1
[Powershell Examples] #Powershell #Examples
<#
.SYNOPSIS
Diffrent methods for displaying relative path
#>
# Existing Path
$PWD | Resolve-Path -Relative
# Replace String
$Path -replace [regex]::Escape((Get-Location).Path), '.'