Skip to content

Instantly share code, notes, and snippets.

View aldrichtr's full-sized avatar

Tim Aldrich aldrichtr

View GitHub Profile
@aldrichtr
aldrichtr / github-actions-notes.md
Created September 13, 2023 08:14 — forked from br3ndonland/github-actions-notes.md
Getting the Gist of GitHub Actions
@aldrichtr
aldrichtr / Matchinfo.Format.ps1xml
Created September 2, 2023 11:34 — forked from mdgrs-mei/Matchinfo.Format.ps1xml
Format file to add links to Select-String outputs
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<View>
<Name>MatchInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.MatchInfo</TypeName>
</ViewSelectedBy>
<CustomControl>
<CustomEntries>
@aldrichtr
aldrichtr / MoonSpinner.ps1
Created September 2, 2023 11:33 — forked from mdgrs-mei/MoonSpinner.ps1
Show a moon spinner on the tab title using DynamicTitle PowerShell module
#Requires -Modules DynamicTitle
$commandStartJob = Start-DTJobCommandPreExecutionCallback -ScriptBlock {
param($command)
(Get-Date), $command
}
$promptJob = Start-DTJobPromptCallback -ScriptBlock {
(Get-Date)
}
@aldrichtr
aldrichtr / ShellIntegration.ps1
Created September 2, 2023 11:32 — forked from mdgrs-mei/ShellIntegration.ps1
Adds escape codes to the prompt for the shell integration
# Reference:
# https://devblogs.microsoft.com/commandline/shell-integration-in-the-windows-terminal/
param
(
[ValidateSet('WindowsTerminal', 'ITerm2')]
[String]$TerminalProgram = 'WindowsTerminal'
)
# Restore hooked functions in case this script is executed accidentally twice
@aldrichtr
aldrichtr / Microsoft.PowerShell_profile.ps1
Created August 15, 2023 20:58 — forked from dprice/Microsoft.PowerShell_profile.ps1
PowerShell Profile #tag PowerShell
$sw = [Diagnostics.Stopwatch]::StartNew()
Write-Host "Updating path..." -foregroundColor DarkGreen
if(!($env:path).contains((Split-Path $PROFILE))) {
$env:path += ";" + (Split-Path $PROFILE)
}
if(!($env:path).contains('D:\dNx\dnx-util;')) {
$env:path += ";" + 'D:\dNx\dnx-util;'
}
if(!($env:path).contains('D:\dNx\dnx-util\test;')) {
$env:path += ";" + 'D:\dNx\dnx-util\test;'

Credit: Mark Kraus
Website: https://get-powershellblog.blogspot.com

Collection Type Guidence

When to use what

  • Use Arrays if you know the element types and have a fixed length and/or known-up-front collection size that will not change.
  • Use ArrayList if you have an unkown collection size with either unknown or mixed type elements.
  • Use a Generic List when know the type of the elements but not the size of the collection.
  • Use a HashTable if you are going to do key based lookups on a collection and don't know the object type of the elements.
  • Use a Dictionary<TKey, TValue> you are going to do key based lookups on a collection and you know the type of the elements.
  • Use a HashSet when you know the type of elements and just want unique values and quick lookups and assignmnets.
@aldrichtr
aldrichtr / PracticalSubmodulesWithGitAndPester.txt
Created July 7, 2023 14:45 — forked from sdoubleday/PracticalSubmodulesWithGitAndPester.txt
Notes on the act of developing with external repositories (i.e. submodules) in git and pester
Notes on the act of developing with external repositories (i.e. submodules) in git and pester
*To the reader:* If you are here looking for expert advice, please leave as swiftly as possible. No such advice is present here. This is purely a set of reminders for the physical(?) act of how I handle working with git submodules and pester tests.
This assumes you are working in PowerShell. Version 5, if it matters, with git 2.10 (or later? It was what I had when I wrote this) and pester.
*Downloading and using a repo with submodules* - When I was getting started with this, I NEVER developed submodules from the main module. I schlepped over to the submodule, branch, develop, merge back to master, and then come back here and update the submodule, and I still think that's a good policy for anything other than mass hotfixes.
Clone the repo as normal. Here, the folder PesterNewFixtureModule will be created in the current folder:
git clone https://github.com/sdoubleday/PesterNewFixtureModule.git PesterNewFixtureModu
#Simple functions and aliases that don't rise to the level of a module that I like having in my PowerShell Profile
function sudo {[CmdletBinding(<#PositionalBinding=$True#>)]PARAM([String]$CommandLine,[Switch]$RunPrior) IF($RunPrior.IsPresent) {$CommandLine = (Get-History | Select-Object -Last 1).CommandLine}; Write-Verbose "Running: $CommandLine"; start-process powershell -verb:Runas "$CommandLine"}
function outlook {. 'C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE' /restore}
function newdir {PARAM($Path) new-item -ItemType Directory -Path $Path }
function ssms2008 {ls 'C:\Program Files\', 'C:\Program Files (x86)\' -Filter micro*Sql*server | ls -Filter '100' | ls -Recurse -Filter *ssms*exe | ii}
#Classes do not always play well in the nested modules section of a manifest. I've had trouble with importing classes in multiple files.
#My current approach is: Create a .ps1 file WITHOUT the standard clauses of BEGIN{} PROCESS{} END{} that uses invoke-expressions:
$invocables = @()
$invocables += $( get-content "$PSScriptRoot\MyFolder\MyClass.psm1" ) -join "`r`n"
$invocables += $( get-content "$PSScriptRoot\MyOtherClassThatDepenedsOnTheFirstOne.psm1" ) -join "`r`n"
foreach ($i in $invocables) { Invoke-Expression -Command $i }
#Classes do not always play well in the nested modules section of a manifest. I've had trouble with importing classes in multiple files.
#My current approach is: Create a .ps1 file WITHOUT the standard clauses of BEGIN{} PROCESS{} END{} that uses invoke-expressions:
$invocables = @()
$invocables += $( get-content "$PSScriptRoot\MyFolder\MyClass.psm1" ) -join "`r`n"
$invocables += $( get-content "$PSScriptRoot\MyOtherClassThatDepenedsOnTheFirstOne.psm1" ) -join "`r`n"
foreach ($i in $invocables) { Invoke-Expression -Command $i }