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 / Get-MonitorDetail.ps1
Last active January 15, 2018 04:57
Iron Scripter Prequel 1
function Get-MonitorDetail {
[OutputType('MonitorDetail')]
[cmdletbinding()]
param(
[parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('Name')]
[string[]]$ComputerName = $env:COMPUTERNAME,
[System.Management.Automation.CredentialAttribute()]
[pscredential]$Credential
@devblackops
devblackops / ComputerInformation.format.ps1xml
Last active March 2, 2018 18:55
Iron Scripter Prequel 2
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>ComputerInformation</Name>
<ViewSelectedBy>
<TypeName>ComputerInformation</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
@devblackops
devblackops / Get-BlogXmlFeed.ps1
Last active January 31, 2018 07:55
Iron Scripter Prequel 3
function Get-BlogXmlFeed {
<#
.SYNOPSIS
Returns posts from the PowerShell.org (or other blog) XML feed.
.DESCRIPTION
Returns posts from the PowerShell.org (or other blog) XML feed and optionally opens the post link in the browser or displays the raw HTML.
.PARAMETER Uri
The XML feed URI to retrieve.
.PARAMETER OpenIn
Open post link in the operating systems' default browser or display the raw HTML.
@devblackops
devblackops / Get-PerformanceCounter.ps1
Last active February 14, 2018 07:42
Solution to Iron Scripter puzzle 5
function Get-PerformanceCounter {
[cmdletbinding(DefaultParameterSetName = 'Computer')]
param(
[parameter(
ParameterSetName = 'Computer',
ValueFromPipeline = $true
)]
[ValidateNotNullOrEmpty()]
[Alias('Name')]
@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 / adauth.ps1
Created February 8, 2019 04:35
PoshBot middleware hook to mark a command as approved is the user is in a certain AD group
param(
$Context,
$Bot
)
$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
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
@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 / rate_limiting_notice.ps1
Last active July 16, 2019 05:49
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
<#
.SYNOPSIS
Suggest Slack threads for talkative users.
.DESCRIPTION
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.
.NOTES
Based on https://stackoverflow.com/questions/667508/whats-a-good-rate-limiting-algorithm
#>
param(