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 / TrackChromeUsage.ps1
Last active December 12, 2019 00:30
Track Chrome processes for graphing at the console.
# 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'
@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(
@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 / 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-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 / 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-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

Keybase proof

I hereby claim:

  • I am devblackops on github.
  • I am devblackops (https://keybase.io/devblackops) on keybase.
  • I have a public key ASDd4DO8BeRC7l3kECkdj8Z6NHEdIeP0dNK50DRr1sBWUwo

To claim this, I am signing this object:

@devblackops
devblackops / Shorten-Url.ps1
Created September 7, 2017 03:51
PoshBot function to shorten a url
function Url {
[PoshBot.BotCommand(
Command = $false,
TriggerType = 'Regex',
Regex = '^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)|[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}[^ ]+'
)]
[cmdletbinding()]
param(
[parameter(Mandatory, ValueFromRemainingArguments)]
[object[]]$Arguments,
@devblackops
devblackops / Custom-Attribute.ps1
Last active January 23, 2017 17:12
Custom attributes attached to PowerShell function
Add-Type -TypeDefinition @"
namespace PoshBot {
public class BotCommand : System.Attribute {
public string Description { get; set; }
}
}
"@
function Foo {
[PoshBot.BotCommand(Description = 'This is a custom function description')]