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
# wrap Measure-Command in & { } for increased measuring performance
Measure-Command { & {
$var = foreach ($i in 0..50000){
$i
}
}}
git update-index --add --chmod=+x install_terraform.sh
$a = @(
'AWS.Tools.Common'
'AWS.Tools.CloudFormation'
'AWS.Tools.CloudFormation'
'AWS.Tools.CloudWatch'
'AWS.Tools.CostExplorer'
'AWS.Tools.EC2'
'AWS.Tools.Installer'
'AWS.Tools.S3'
'AWS.Tools.SecretsManager'
Get-ChildItem -Filter *.ps1 | ForEach-Object {
$ast = [System.Management.Automation.Language.Parser]::ParseFile($_.FullName, [ref]$null, [ref]$null)
$ast.FindAll({ param($sa) $sa -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $false) | ForEach-Object {
# Define functions
New-Item -Path Function:\ -Name $_.Name -Value $_.Body.GetScriptBlock()
}
}
The default branch has been renamed!
master is now named main
If you have a local clone, you can update it by running the following commands.
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
@techthoughts2
techthoughts2 / ps_plex_backup
Last active December 2, 2021 04:25
This quick script will perform a backup of the plex registry settings as well as a complete backup of your Plex media server data. This can be tied to a task scheduler for ongoing backups so you never have to worry about your Plex server data. This d
#Requires –Modules PoshGram
#https://support.plex.tv/articles/201539237-backing-up-plex-media-server-data/
#https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/
# if you don't want to send yourself telegram messages the telegram portion can be removed
Import-Module -Name PoshGram
$token = '111111111:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$chat_id = '-111111111'
It 'should run the expected commands if an error is encountered' {
Mock -CommandName Invoke-RestMethod {
throw 'Fake Error'
} #endMock
Mock -CommandName Write-Warning { }
Mock -CommandName Write-Error { }
$sendTelegramContactSplat = @{
BotToken = $token
ChatID = $chat
PhoneNumber = $phone
#-----------------------------------------------------------------------------
Mock Invoke-RestMethod {
[System.Exception]$exception = "The remote server returned an error: (400) Bad Request."
[System.String]$errorId = 'BadRequest'
[Management.Automation.ErrorCategory]$errorCategory = [Management.Automation.ErrorCategory]::InvalidOperation
[System.Object]$target = 'Whatevs'
$errorRecord = New-Object Management.Automation.ErrorRecord ($exception, $errorID, $errorCategory, $target)
[System.Management.Automation.ErrorDetails]$errorDetails = '{"message":"Username does not exist: [user]"}'
$errorRecord.ErrorDetails = $errorDetails
throw $errorRecord
$script:mockCalled = 0
$mockInvoke = {
$script:mockCalled++
if ($script:mockCalled -eq 1) {
return $false
}
elseif ($script:mockCalled -eq 2) {
return $true
}
}
@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;
}