Skip to content

Instantly share code, notes, and snippets.

@robderickson
robderickson / Add-ACEtoACL.ps1
Created December 9, 2016 14:03
Script to add an entry to an access control list. Wrote this four years ago, so definitely not my best work.
<#
.SYNOPSIS
Creates an access control entry (ACE) and adds it to an access control list (ACL).
.DESCRIPTION
Creates an access control entry (ACE) and adds it to an access control list (ACL).
.PARAMETER Rights
A right or list of rights to be allowed or denied by the ACE.
@robderickson
robderickson / HolidayHackHowTo2016.md
Last active January 4, 2017 17:36
SANS 2016 Holiday Hack Challenge

SANS 2016 Holiday Hack Challenge

Challenger: GilGrenade

Part 1: A Most Curious Business Card

Santa's business card reveals usernames for his Twitter and Instagram social media sites.

Twitter

@robderickson
robderickson / DotSourceExample.psm1
Created June 8, 2017 13:16
Example of a PowerShell script module that uses dot sourcing
$Public = @(Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue)
$Private = @(Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue)
foreach ($import in @($Public + $Private)) {
try {
. $import.fullname
} catch {
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
@robderickson
robderickson / ConfiguringVim.md
Last active March 26, 2019 09:13
Confgure VIM for Puppet on CentOS 7

Confgure VIM for Puppet on CentOS 7

Install VIM and Git

sudo yum install vim-enhanced -y
sudo yum install git -y

Download and install Puppet plugin for VIM

@robderickson
robderickson / gist:582efb78a71aa2a5a12bfbb050e22ec4
Created February 19, 2018 12:54
Add permission for single user to many mailboxes
function Set-CustomUserMailboxPermission {
[cmdletbinding()]
param (
[parameter(ValueFromPipeline,Mandatory)]
[string]$User,
[parameter(ValueFromPipeline,Mandatory)]
[string[]]$Mailbox,
[parameter(Mandatory)]
@robderickson
robderickson / AlignmentExamples.ps1
Created July 31, 2018 15:09
Key/value alignment
@{
Something = 'this'
SomethingElse = 'that'
}
# Get some events
$Computer = 'dc01'
$User = 'rob'
$Events = Get-WinEvent -ComputerName $Computer -LogName Security -FilterXPath "*[System[(EventID='4776']][EventData[Data='$User']]"
$xml = [xml]$Events[0].ToXml()

The document looks like this.

@robderickson
robderickson / Get-FailedLogonEvent.ps1
Created July 31, 2018 18:29
Get failed logon events 4771 and 4776, and return the TargetUserName and Workstation or IPAddress values recorded in the events.
[CmdletBinding()]
param(
[string[]]$ComputerName,
[string]$SamAccountName
)
PROCESS {
foreach ($computer in $ComputerName) {
$events = Get-WinEvent -ComputerName $computer -LogName Security -FilterXPath "*[System[(EventID='4771' or EventID='4776')]][EventData[Data='$SamAccountName']]"
foreach ($event in $events) {
@robderickson
robderickson / UpdateSplat.ps1
Created September 3, 2018 01:14
Adding key to multiple hash tables
if ($ComputerName) {
$GetADRootDSESplat['Server'] = $ComputerName
$GetADObjectSplat['Server'] = $ComputerName
$SetADObjectSplat['Server'] = $ComputerName
}
@robderickson
robderickson / HtmlEmailStyle.ps1
Created September 21, 2018 19:35
HtmlEmailStyle
$Html = @"
<html>
<head>
<style>
body {
font-family: Calibri, sans-serif;
font-size: 11pt;
}
h2 {