Skip to content

Instantly share code, notes, and snippets.

View rayterrill's full-sized avatar

Ray Terrill rayterrill

View GitHub Profile
@rayterrill
rayterrill / getCurrentExternalIPAddress.ps1
Created April 8, 2016 02:30
PowerShell - Get Current External IP Address
#h/t: http://tfl09.blogspot.com/2008/07/finding-your-external-ip-address-with.html
function getCurrentExternalIPAddress() {
$wc=New-Object net.webclient
$wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"
}
$resourceGroupName = "TESTSERVERS"
$location = "West US"
$storageType = "Standard_GRS"
function createStorageAccount($storageAccountPrefix) {
$storageAccountCreated = $False
#storage account names need to be globally unique
#loop until we find a storage account name that works
while ($storageAccountCreated -eq $False) {
function checkADGroup($adLDAPHost, $ldap_dn, $queryUser, $queryPassword, $user, $group) {
// Connect to AD
$ldap = ldap_connect($adLDAPHost) or die("Could not connect to LDAP");
ldap_bind($ldap,$queryUser,$queryPassword) or die("Could not bind to LDAP");
// Search AD
$results = ldap_search($ldap,$ldap_dn,"(samaccountname=$user)",array("memberof","primarygroupid"));
$entries = ldap_get_entries($ldap, $results);
// No information found, bad user
@rayterrill
rayterrill / readSPSTButtonArduino.ino
Created April 27, 2016 04:21
How to read a SPST button with an Arduino
#check out http://fritzing.org/projects/read-spst-arduino for wiring info
const int buttonPin = 5;
int buttonState = 0;
void setup() {
Serial.begin(115200);
//initialize button pin
pinMode (buttonPin, INPUT_PULLUP);
Import-Module AWSPowerShell
#get a date 90 days ago to use to calculate old credentials
$date90DaysAgo = (Get-Date).AddDays(-90)
#gather all of our iam users
$users = Get-IAMUsers
#iterate each of my uesrs
foreach ($u in $users) {
#grab all the keys for a user
Import-Module AWSPowerShell
Set-AWSCredentials -AccessKey myAccessKey -SecretKey mySecretKey -StoreAs myCredentialName
Initialize-AWSDefaults -ProfileName myCredentialName -Region us-west-2
#get the CPU Steal Time value from VMWare
$stolenProperty = Get-CimInstance Win32_PerfRawData_vmGuestLib_VCPU -Property CpuStolenMs | Select-Object -Property CpuStolenMs
Write-Host $stolenProperty.CpuStolenMs
function Install-WMF5 ($WMF5location, $server) {
Invoke-Command -ComputerName $server -ScriptBlock { New-Item c:\temp\WMF5 -Type Directory -Force -ErrorAction 'SilentlyContinue' | Out-Null }
$serverTempLocation = "\\$($server)\c`$\Temp\WMF5\"
#copy the wmf5 file from a central location to our server at c:\temp\wmf5
Copy-Item $WMF5location $serverTempLocation
#use wusa to extract the cab file to install the wmf5 package
$scriptBlock = { Start-Process -FilePath 'wusa.exe' -ArgumentList "c:\temp\WMF5\Win8.1AndW2K12R2-KB3134758-x64.msu /extract:C:\temp\WMF5\" -verb runAs -Wait -PassThru }
#I spent many hours today trying to grok Handlers in Chef, and get a functional email handler in place.
#This is a brain dump of my configuration in the hopes that others find it useful (and to remind myself).
#cd to your repo's cookbooks directory, download the chef_handler cookbook, and un-tarzip
knife cookbook site download chef_handler
tar -xvzf chef_handler.tgz
#create a send_email.rb handler in your default chef_hander handler directory with the below results
#replace EMAILADDRESS, DOMAIN, EMAILSERVER with values for your environment
vi ~/repo/cookbooks/chef_handler/files/default/handlers/send_email.rb
#BACKSTORY:
#I wanted to get a way to quickly and centrally see how my Chef runs might be going.
#SUMMARY:
#1. I built a quick web service in PHP (details not pertinent here), that takes parameters node, status, and runlist, and saves the results to a database for reporting purposes
#2. I configured Chef to call my PHP web service on each successful and failed chef-client run using Chef.event_handler in my default.rb
#created a helper.rb at ~/POP/cookbooks/MyCookbook/libraries/helper.rb
######################################################################
require 'net/http'