Skip to content

Instantly share code, notes, and snippets.

@toenuff
toenuff / hgrep.ps1
Last active December 24, 2015 00:09
Hgrep is a function that provides similar functionality to the unix commands history |grep something
# http://powertoe.wordpress.com/2013/09/26/powerbits-10-history-grep-or-hgrep-in-powershell/
function hgrep {
param(
[Parameter(Mandatory=$false, Position=0)]
[string]$Regex,
[Parameter(Mandatory=$false)]
[switch]$Full
)
$commands = get-history |?{$_.commandline -match $regex}
@toenuff
toenuff / currentdir
Last active December 24, 2015 00:19
The following snippet gets the current directory whether or not it's run from a script or a PowerShell host. I put this at the top of nearly every script I write. Blogged as powerbit #9 here: http://powertoe.wordpress.com/2012/11/02/powerbits-9-set-the-current-directory-to-the-script-directory-or-the-current-directory-if-run-in-a-session/
# http://powertoe.wordpress.com/2012/11/02/powerbits-9-set-the-current-directory-to-the-script-directory-or-the-current-directory-if-run-in-a-session/
$currdir = ''
if ($MyInvocation.MyCommand.Path) {
$currdir = Split-Path $MyInvocation.MyCommand.Path
} else {
$currdir = $pwd -replace '^\S+::',''
}
@toenuff
toenuff / gist:7536659
Created November 18, 2013 22:40
Write-Trace - Write a trace message with PowerShell
function Write-Trace {
param(
[Parameter(Mandatory=$true, Position=0, ValueFromRemainingArguments=$true)]
[string]$message,
[Parameter(Mandatory=$false)]
[string]$category="PS Script"
)
[System.Diagnostics.Debug]::WriteLine($message, $category)
}
@toenuff
toenuff / randomwinners
Created January 31, 2014 21:07
NYC PowerShell User Group gist for giveaway lottery - nice for football pools too :P
$firstnumber = 0
$lastnumber = 9
$numberofwinners = 10
$numbers = new-object System.collections.arraylist
($firstnumber..$lastnumber) |%{ $numbers.add($_) |out-null}
function Get-NextNumber {
param (
[Parameter(Mandatory=$true, Position=0)]
@toenuff
toenuff / profile.ps1
Last active August 29, 2015 13:57
PowerShell Profile
(("1*0x26*1x3*2x4*3x1*4x1*2x2*1x1*2x1*4x4*3x3*2x21*1x1*0x20*1x1*2x2*4x3*5x5*6x2*7x6*1x2*8x5*6x3*5x2*4x1*2x15*1x1*0x17*1x1*2x1*4x1*5x10*6x2*7x1*1x1*9x4*1x1*10x1*1x2*8x10*6x1*5x1*4x1*2x13*1x1*0x16*1x1*4x12*6x2*7x2*1x1*11x1*8x2*5x1*7x1*11x2*1x2*8x12*6x1*4x11*1x1*0x14*1x1*2x1*7x12*6x2*7x3*1x1*9x1*12x2*13x1*14x1*10x3*1x2*8x12*6x1*8x1*2x9*1x1*0x14*1x1*7x13*6x2*9x4*1x2*8x2*7x5*1x2*10x13*6x1*8x9*1x1*0x12*1x1*4x15*6x2*8x4*1x1*9x2*15x1*10x4*1x2*7x15*6x1*4x7*1x1*0x11*1x1*4x17*6x2*8x2*1x1*7x1*1x2*16x1*1x1*8x2*1x2*7x17*6x1*4x7*1x1*0x10*1x1*4x19*6x2*8x1*7x6*1x1*8x2*7x19*6x1*4x5*1x1*0x9*1x1*2x1*6x1*7x1*11x10*6x1*7x1*8x6*6x1*9x3*1x1*7x1*8x3*1x1*10x6*6x1*7x1*8x10*6x1*11x1*8x1*6x1*2x5*1x1*0x9*1x1*11x1*7x1*1x1*11x1*6x1*7x1*8x1*6x1*7x1*8x1*6x1*7x1*8x1*7x2*1x1*8x1*6x1*7x1*8x2*6x1*8x2*1x1*11x2*1x1*11x2*1x1*7x2*6x1*7x1*8x1*6x1*7x2*1x1*8x1*7x1*8x1*6x1*7x1*8x1*6x1*7x1*8x1*6x1*11x1*1x1*8x1*11x5*1x1*0x9*1x1*17x2*1x1*11x1*7x2*1x1*16x2*1x1*16x2*1x1*17x3*1x1*16x2*1x1*8x1*6x1*8x1*11x1*1x1*11x2*1x1*11x1*1x1*11x1*7x1*6x1*7x2*1x1*16x3*1x1*17x
@toenuff
toenuff / conemukeymap.xml
Created March 7, 2014 14:40
Conemu keymap
<?xml version="1.0" encoding="utf-8"?>
<key name="Software">
<key name="ConEmu">
<key name=".Vanilla" modified="2014-03-07 09:22:48" build="140304">
<value name="ColorTable00" type="dword" data="00000000"/>
<value name="ColorTable01" type="dword" data="00800000"/>
<value name="ColorTable02" type="dword" data="00008000"/>
<value name="ColorTable03" type="dword" data="00808000"/>
<value name="ColorTable04" type="dword" data="00000080"/>
set shell=powershell
set shellcmdflag=-command
set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
set autoindent " ai: indent to match previous line
set cindent " cin: Use C-indenting
set cinkeys=0{,0},0),!^F,o,O,e " cink: Perl-friendly reindent keys
set cinoptions=t0,+4,(0,)60,u0,*100 " cino: all sorts of options
set cinwords=if,else,while,do,for,elsif,sub
set comments=n:# " com: Perlish comments
@toenuff
toenuff / setbreakpoint.py
Created July 11, 2014 10:52
Python - Set breakpoint
import pdb; pdb.set_trace()
@toenuff
toenuff / samplecred
Last active August 29, 2015 14:20
Example of putting -Credential in function
$class = new-object psobject @{credential=$null}
function samplecred {
param(
[Parameter(Mandatory=$false)]
[ValidateScript({("String","PSCredential") -contains $_.gettype().name})]
[Object] $Credential
)
if ($Credential) {
switch ($Credential.gettype().name) {
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA7oei2KnmNsq4pZVtcwtDN0zIrEmv5TgMxdLQtdIszqO/UJbp
Lbf4LG+DtT7eVmzmN3rSWV9Q7P7UdAds0j03c9sAwjprMuv5F1MzyC1rNQct5M5m
X0X0Scylan9HVccjTXt6Yr+IPni8PNOs0rwhqRB0TEtJuP2IYuzeg5Z2LWxnAVjL
5uNd9HMpuDwVHDMibpeMOomr2ePqdUPAK+ZRQbUYVvnR6fkzSKehcTvnKG6P1qhO
ifx6dsmls9HqrRpfBXmItAUaMO7VrQAjFybYgr8dHdVewLJqM2EmyN2buxEMIckp
afxb042mZbukJqZXEAZo2IYeee4NgSPV7fXhGwIDAQABAoIBAQDXg0s6MT+kb8Mn
MHyEPj/L3h9NswIuu1anAhO6w5viVAaOPNuPiDG9jD/W6WefdKMIq3sUbs9CYff4
oaDLz62jitMDqh6jEpurXGxjx82eSs9HdMj/+cd/SlyGfVspgFRANHlecSkbMKD6
4FG80WgkRY6eREPm1YN9xgBBqhc6b4GGZ2+hcVhkfYdnfmACy9+tIF6yHG5c4VPE