Skip to content

Instantly share code, notes, and snippets.

View shoddyguard's full-sized avatar

Steve Brown shoddyguard

View GitHub Profile
@shoddyguard
shoddyguard / Instructions.txt
Created August 11, 2021 22:44
Regex matching Terraform blocks in .NET
This a crude but reasonably effective way of extracting blocks from Terraform/HCL in something like PowerShell.
I'm sure there are edge cases that are not covered here but this is handy when you want to parse Terraform configurations en masse.
In my particular case I needed to replace all `github_branch_protection` resources with `github_branch_protection_v3` resources due to the current GraphQL implementation of the GitHub Terraform provider causing lengthy Terraform runs. :(
@shoddyguard
shoddyguard / Install-PowerMonitor.ps1
Created June 22, 2020 23:26
Simple event monitor for HID UPS such as Salicru Home
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Installs a basic HID UPS monitor that triggers a script in the event of power loss or battery drain.
.DESCRIPTION
Recently my UPS software (Powermaster) stopped working for my Salicru 850 home after some Windows update knocked it out (Server 2019).
I noticed it was still detected as a HID battery device, so I wrote this simple script to trigger a secondary script in the event of power loss.
This script creates a permanent event consumer (persists through reboots) to keep an eye on the power status and then trigger a script on either AC Power or battery threshold falling below a certain level.
.NOTES
This script is quite basic and I am using it in conjuction with Puppet to ensure things get set correctly, I've done my best to adapt it into a gist that hopefully someone will find handy.