Skip to content

Instantly share code, notes, and snippets.

View devblackops's full-sized avatar
🎯
Lookin' for code in all the wrong places

Brandon Olin devblackops

🎯
Lookin' for code in all the wrong places
View GitHub Profile
@devblackops
devblackops / redalert.ps1
Last active August 15, 2023 08:02
Display highly visible notification if the last command failed in the Microsoft Terminal using PowerShell
# Put this code in your PowerShell profile script
# This requires the MSTerminalSettings module which you can download with:
# Install-Module MSTerminalSettings -Scope CurrentUser -Repository PSGallery
Import-Module MSTerminalSettings
$msTermProfileName = 'pwsh' # Replace with whatever Terminal profile name you're using
$msTermProfile = Get-MSTerminalProfile -Name $msTermProfileName
$script:bombThrown = $false
function prompt {
if ($? -eq $false) {
@devblackops
devblackops / prompt.ps1
Last active February 28, 2023 23:50
My basic prompt
Import-Module posh-git
function prompt {
# The status of the last command run
$lastSuccess = $?
# Colors for prompt
$color = @{
Reset = "`e[0m"
Red = "`e[31;1m"
Green = "`e[32;1m"
@devblackops
devblackops / Get-MostCommonCommands.ps1
Created June 13, 2019 23:07
Get your most common PowerShell commands by inspecting your PSReadLine history
$err=$null
[System.Management.Automation.PSParser]::Tokenize((Get-Content (Get-PSReadLineOption).HistorySavePath),[ref]$err) |
Where-Object {$_.type -eq 'command'} |
Select-Object Content | Group-Object Content |
Sort-Object Count, Name -Descending | Select-Object Count, Name -First 20
# Registered an AAD group with Priviledged Identity Management (PIM)
function Get-PimToken {
<#
.SYNOPSIS
Gets the Azure auth token for PIM.
#>
[cmdletbinding()]
param()
@devblackops
devblackops / Steps.md
Last active August 29, 2022 07:33
PoshBot container in Kubernetes

PoshBot and Kubernetes

This gist is a quick example of how to run PoshBot inside Kubernetes using minikube. This will deploy PoshBot v0.11.3 inside a Linux container and expose most configuration options as environment variables. The Slack bot token is stored as a Kubernetes secret.

Secrets

Create a Kubernetes secret which includes your Slack bot token. This secret will be later be exposed to the pod as the POSHBOT_SLACK_TOKEN environment variable.

@devblackops
devblackops / chefquery.ps1
Created January 7, 2016 00:25
PowerShell script to query Chef nodes via REST API. Assumes you have the BouncyCastle.Crypto.dll in the same folder as the script.
function Get-Base64 {
param (
$data
)
# if the $data is a string then ensure it is a byte array
if ($data.GetType().Name -eq "String") {
$data = [System.Text.Encoding]::UTF8.GetBytes($data)
}
[cmdletbinding()]
param()
function Connect-SlackRtm {
[cmdletbinding()]
param(
[string]$Token
)
$loginData = @{}
$tenant = '<tenant-id>'
$subscription = '<subscription-id>'
$clientId = '<client-id>'
$clientSecret = '<client-secret>'
# Log into Azure w/ Service Principal
$creds = [pscredential]::new($clientId, ($clientSecret | ConvertTo-SecureString -AsPlainText -Force))
Connect-AzAccount -TenantId $tenant -SubscriptionId $subscription -Credential $creds -ServicePrincipal > $null
# Get auth token
@devblackops
devblackops / SlackRtmTlsBugRepo.ps1
Created March 5, 2020 17:23
Minimal reproduction of connecting to Slack's RTM websocket API to receive messages
[cmdletbinding()]
param()
function Connect-SlackRtm {
[cmdletbinding()]
param(
[string]$Token
)
$loginData = @{}
@devblackops
devblackops / tf_plan.txt
Created January 15, 2020 17:12
Azure Front Door Terraform plan output
# azurerm_frontdoor.fd will be created
+ resource "azurerm_frontdoor" "fd" {
+ cname = (known after apply)
+ enforce_backend_pools_certificate_name_check = true
+ id = (known after apply)
+ load_balancer_enabled = true
+ location = "eastus"
+ name = "XXXXX-fd1"
+ resource_group_name = "tf_XXXXX"