Skip to content

Instantly share code, notes, and snippets.

Avatar
🕵️‍♂️
Investigating a better artifact workflow

Jake Morrison techthoughts2

🕵️‍♂️
Investigating a better artifact workflow
View GitHub Profile
@techthoughts2
techthoughts2 / update_azure_components
Last active May 13, 2022
These few lines will quickly update your local development environment to the latest Azure components.
View update_azure_components
winget upgrade Microsoft.AzureStorageExplorer --silent --accept-package-agreements --accept-source-agreements
winget upgrade Microsoft.AzureCLI --silent --accept-package-agreements --accept-source-agreements
winget upgrade Microsoft.Bicep --silent --accept-package-agreements --accept-source-agreements
az bicep upgrade
Update-Module Az
View pwsh_ofs
# OFS - special variable that contains the string to be used as the output field seperator
$OFS = '...';$array = ('first','last');[string]$array; Remove-Variable OFS
$array = ('first','last');[string]$array;
View pwsh_measure_command
# wrap Measure-Command in & { } for increased measuring performance
Measure-Command { & {
$var = foreach ($i in 0..50000){
$i
}
}}
View git_exec_sh
git update-index --add --chmod=+x install_terraform.sh
View powershell_aws_tools_install
$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'
View lift_functions
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()
}
}
View github_branch_rename
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 Dec 2, 2021
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
View ps_plex_backup
#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'
View pester_assert_commands
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
View mock_exception
#-----------------------------------------------------------------------------
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