Skip to content

Instantly share code, notes, and snippets.

View techthoughts2's full-sized avatar
🕵️‍♂️
Investigating a better artifact workflow

Jake Morrison techthoughts2

🕵️‍♂️
Investigating a better artifact workflow
View GitHub Profile
@techthoughts2
techthoughts2 / pwsh_params
Last active November 15, 2021 15:36
Get all of the parameter values passed into a function
# Get the command name
$CommandName = $PSCmdlet.MyInvocation.InvocationName;
# Get the list of parameters for the command
$ParameterList = (Get-Command -Name $CommandName).Parameters;
# Grab each parameter value, using Get-Variable
foreach ($Parameter in $ParameterList) {
Get-Variable -Name $Parameter.Values.Name -ErrorAction SilentlyContinue;
#Get-Variable -Name $ParameterList;
}
@techthoughts2
techthoughts2 / pester_parameter_mock
Last active January 5, 2023 04:55
Pester test a command that should be called with certain parameters
# test a command that should be called with certain parameters
#------------------------------------------------------------------------------
It 'should call the API with the expected parameters' {
Mock -CommandName Invoke-RestMethod {
} -Verifiable -ParameterFilter { $Uri -like 'https://api.telegram.org/bot*getStickerSet*' }
# "https://api.telegram.org/bot$BotToken/getStickerSet"
$getTelegramStickerPackInfoSplat = @{
BotToken = $token
StickerSetName = 'STPicard'
}
# use generic list to add objects in a performant way
$starTrekShowInfo = New-Object System.Collections.Generic.List[string]
$starTrekShowInfo.Add('Star Trek: The Next Generation')
# use custom objects for high performance adds of custom object
$choiceArray = New-Object System.Collections.Generic.List[PSCustomObject]
#------------------------------------------------------------------------------
# old method which should no longer be used IAW:
# https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=net-6.0
# adding stuff to emtpy array objects quickly
$GetVM={Get-VM | Select-Object -ExpandProperty Name}
$AutoCompleteVM = @{
CommandName = 'New-Foo'
ParameterName = 'VMName'
ScriptBlock = $GetVM
}
Register-ArgumentCompleter @AutoCompleteVM
[string[]]('222.1.3.4','1.2.3.4' | % {[Version]$PSItem} | sort)
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
@techthoughts2
techthoughts2 / settings.json
Last active December 28, 2024 05:15
Current Windows Terminal Settings
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command":
{
"action": "copy",
"singleLine": false
@techthoughts2
techthoughts2 / python.json
Last active December 10, 2024 02:29
Collection of Python Snippets for VSCode
{
"if": {
"prefix": "if",
"body": ["if ${1:expression}:", "\t${2:pass}"],
"description": "Code snippet for an if statement"
},
"if/else": {
"prefix": "if/else",
"body": ["if ${1:condition}:", "\t${2:pass}", "else:", "\t${3:pass}"],
"description": "Code snippet for an if statement with else"
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
// {
// "type": "text",
// "style": "plain",
@techthoughts2
techthoughts2 / ws_setup.ps1
Last active March 2, 2025 08:29
This PowerShell script will setup a fresh workstation with everything needed to sucessfully work and be a DevOps Master day-to-day.
#region installs
# core tech choco installs
$script:chocoCoreTech = @(
# 'vscode' # visual studio code
# 'python' # python
# '7zip' # file archiver with good compression ratio
# 'git' # git for windows
# 'firefox' # firefox browser
)