Skip to content

Instantly share code, notes, and snippets.

Lookin' for code in all the wrong places

Brandon Olin devblackops

Lookin' for code in all the wrong places
Block or report user

Report or block devblackops

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
devblackops / TrackChromeUsage.ps1
Last active Dec 12, 2019
Track Chrome processes for graphing at the console.
View TrackChromeUsage.ps1
# Put these functions in the profile.ps1 to start and stop Chrome usage tracking.
# Display your Chrome usage by running "Show-ChromeUsage"
# Track Chrome usage
function Start-ChromeUsageTracking {
$job = Start-Job -Name ChromeTracker -ScriptBlock {
while ($true) {
$now = [datetime]::Now.ToString('s')
$tabs = (Get-Process chrome -ErrorAction SilentlyContinue).Count
$log = Join-Path ([IO.Path]::GetTempPath()) 'chrome_usage.csv'
View AzureAD_pwsh_repro.ps1
$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 / rate_limiting_notice.ps1
Last active Jul 16, 2019
PoshBot middlware hook to notify chatty people in a Slack channel to use threaded conversations if they post too many messages in a short time interval
View rate_limiting_notice.ps1
Suggest Slack threads for talkative users.
This middleware tracks how many messages (x) users send per (y) amount of time.
If a user goes over the threshold, we'll send a message suggesting that Slack threads should be used.
Based on
devblackops / redalert.ps1
Last active Jul 1, 2019
Display highly visible notification if the last command failed in the Microsoft Terminal using PowerShell
View redalert.ps1
# 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 / Get-MostCommonCommands.ps1
Created Jun 13, 2019
Get your most common PowerShell commands by inspecting your PSReadLine history
View Get-MostCommonCommands.ps1
[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
devblackops / gist:f8523fda1631b6b64de50ed89293d218
Created Apr 3, 2019
Terraform plan fails when Azure resource group has a ReadOnly management lock on it
View gist:f8523fda1631b6b64de50ed89293d218
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
random_string.stg_name: Refreshing state... (ID: none)
azurerm_resource_group.rsg: Refreshing state... (ID: /subscriptions/af5751f7-5e57-4492-a2cc-e8618f11110d/resourceGroups/scratch)
azurerm_storage_account.standard-storage: Refreshing state... (ID: /subscriptions/0f553e2c-4844-4a0f-bd62-...orage/storageAccounts/hnzj1vqqbqiaqli8)
Error: Error refreshing state: 1 error(s) occurred:
devblackops / prompt.ps1
Last active Aug 6, 2019
My basic prompt
View prompt.ps1
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 / adauth.ps1
Created Feb 8, 2019
PoshBot middleware hook to mark a command as approved is the user is in a certain AD group
View adauth.ps1
$user = $Context.Message.FromName
$adGroup = 'botusers'
$userGroups = (New-Object System.DirectoryServices.DirectorySearcher("(&(objectCategory=User)(samAccountName=$user)))")).FindOne().GetDirectoryEntry().memberOf
if (-not ($userGroups -contains $adGroup)) {
devblackops /
Last active Nov 9, 2018
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.


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 / Get-PerformanceCounter.ps1
Last active Feb 14, 2018
Solution to Iron Scripter puzzle 5
View Get-PerformanceCounter.ps1
function Get-PerformanceCounter {
[cmdletbinding(DefaultParameterSetName = 'Computer')]
ParameterSetName = 'Computer',
ValueFromPipeline = $true
You can’t perform that action at this time.