Skip to content

Instantly share code, notes, and snippets.

@rpunt
rpunt / phoh.ps1
Created April 7, 2014 20:13
Powershell hash of hashes
$entries = @{}
import-csv $csv | % {
$entries.add(($adpentry.EEfile_Number),(@{
fname = $_."First Name"
lname = $_."Last Name"
department = $_.Department
location = $_.Location
manager = $_.Manager
title = $_."Job Title"
}))
@rpunt
rpunt / newrelic_post.pl
Created April 29, 2014 14:31
Post deployment info the NewRelic
# New Relic deployment events
my $ua = LWP::UserAgent->new;
$response = $ua->request(POST 'https://api.newrelic.com/deployments.xml',
Content => [
'deployment[application_id]' => $APPID,
'deployment[description]' => 'deployment message',
'deployment[revision]' => $RELEASE_VERSION,
'deployment[user]' => 'Jenkins'
],
'x-api-key' => $APIKEY
@rpunt
rpunt / encode.ps1
Created May 20, 2015 02:39
Batch-encode all .MKV containers in a directory to AppleTV-compatible .MP4
$scandir = "d:\video"
$outputdir = "d:\encoded"
$filelist = Get-ChildItem $scandir -filter *.mkv -recurse
$num = $filelist | measure
$filecount = $num.count
$i = 0;
ForEach ($file in $filelist)
{
@rpunt
rpunt / gist:85ab824375936a2caebf
Created July 17, 2015 17:07
Mirror a CRL, and use the "This update" field as the file's mod-time
curl http://site.com/file.crl -o /var/www/file.crl
lastmod=`openssl crl -inform DER -text -noout -in /var/www/file.crl | grep "Last Update" | awk '{ print "date -d \""$3FS$4FS$5FS$6"\" +%Y%m%d%H%M" }' | bash`
touch -mt $lastmod /var/www/file.crl
@rpunt
rpunt / PowerShell Console Transcript.ps1
Last active December 14, 2015 19:09
Writes a log of the console output from a powershell script to $PWD. Very useful for unattended scripts.
$log=Join-Path (Get-ChildItem $MyInvocation.MyCommand.Definition).Directory (Get-ChildItem $MyInvocation.MyCommand.Definition).Basename
Start-Transcript "$log.log"
@rpunt
rpunt / Verify User Credentials.ps1
Last active December 14, 2015 19:09
Verify the user running the script is a local admin before proceeding
[CmdletBinding()]
param (
[parameter(Mandatory=$true)][string]$adminuser,
[parameter(Mandatory=$true)][string]$adminpassword
)
$computer = gc env:computername
# did you enter valid credentials for a local user?
[Reflection.Assembly]::LoadFile('C:\Windows\assembly\GAC_MSIL\System.DirectoryServices\2.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.dll')
@rpunt
rpunt / 01-preseed-LVM-on-software-RAID.sh
Last active December 14, 2015 19:29
# This is a preseed partman recipe that will later allow the created on # LVM-on-software-RAID, somethat that wasn't possible directly in the # preseed at the time (~2003)
# This is a preseed partman recipe that will later allow the created on
# LVM-on-software-RAID, somethat that wasn't possible directly in the
# preseed at the time (~2003)
d-i lvmcfg/activevg boolean false
d-i lvmcfg/vgdelete_names select vg00
d-i lvmcfg/vgcreate_name string vg00
d-i lvmcfg/vgdelete_confirm boolean true
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
@rpunt
rpunt / retrieve_exchange_room_lists.mm
Last active December 15, 2015 00:59
Retrieve a list of roomlists from Exchange 2010 via SOAP.
// Retrieve a list of roomlists from Exchange 2010 via SOAP.
// This method then uses SMXMLDocument to retrieve the e-mail addresses for those roomlists,
// which can be used to query the individual rooms
// DEPENDENCIES: AFNetworking v1 (https://github.com/AFNetworking/AFNetworking)
// SMXMLDocument (https://github.com/nfarina/xmldocument)
//
// NOTE: I used AFHTTPRequestOperation instead of AFXMLRequestOperation because I wanted the XML, not an XML parser
// (which is what AFXMLRequestOperation returns)
- (void) readRoomLists {
@rpunt
rpunt / conferenceroom_schedule_SOAP_message.mm
Created March 16, 2013 14:07
A SOAP message that will retrieve a conference room's schedule for the day in Exchange 2010.
// for some reason, Exchange Web Services seems to ignore the DST-specific bias settings, and only refer to the
// master bias.
// set the master bias here.
int bias = abs([[NSTimeZone systemTimeZone] secondsFromGMT] / 60);
NSString *soapMessage = [NSString stringWithFormat:@""
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
@"<soap:Body>"
@"<GetUserAvailabilityRequest xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
@rpunt
rpunt / retrieve_rooms_from_roomlists.mm
Created March 16, 2013 14:20
A SOAP message that will retrieve a list of rooms in a roomlist from Exchange 2010.
// given the e-mail address of a roomlist, this SOAP message will retrieve the member rooms.
NSString *roomlist = @"roomlist1@domain.tld" // this is the e-mail address of the room list you're querying
NSLog(@"querying roomlist %@", roomlist);
NSString *soapMessage = [NSString stringWithFormat:@""
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
@"<soap:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
@"<soap:Header>"
@"<t:RequestServerVersion Version =\"Exchange2010_SP2\"/>"
@"</soap:Header>"