Skip to content

Instantly share code, notes, and snippets.

@Erreinion
Erreinion / gist:6022121
Created July 17, 2013 16:21
Get 10 random records from SQL - different set of 10 every time it is run.
SELECT TOP 10 *
FROM Table
ORDER BY NEWID()
$user = Get-WMIObject Win32_UserAccount -Filter "Name='$oldName'"
$result = $user.Rename($newName)
if ($result.ReturnValue -eq 0) {
return $user
# you may just print a message here
}
@Erreinion
Erreinion / gist:6022554
Created July 17, 2013 17:19
Remotely rename local account names, array iteration,
$comps = @("comp2", "comp1")
$comps | Foreach {
if(Test-Connection $_ -q -count 1){
$user = Get-WMIObject Win32_UserAccount -computername $_ -Filter "Name='@oldname'"
$result = $user.Rename('@newname')
if ($result.ReturnValue -eq 0) {
return Get-WMIObject Win32_UserAccount -computername $_ -Filter "Name='@newname'"
}
}
@Erreinion
Erreinion / gist:6117932
Created July 30, 2013 23:19
Get username from email address: use split
foo = "john@example.com"
foo.split('@')[0]
@Erreinion
Erreinion / gist:6147743
Last active December 20, 2015 14:38
Example of 'private' function in Python. _ = don't expose, __ = hide. http://stackoverflow.com/a/70900/1060378
class Foo(object):
def __init__(self):
self.__baz = 42
def foo(self):
print self.__baz
class Bar(Foo):
def __init__(self):
super(Bar, self).__init__()
self.__baz = 21
@Erreinion
Erreinion / HTMLClipboard.py
Last active November 24, 2023 22:35
HTMLClipboard with updates for Python 3. Includes exception handling for locked clipboard. Improvement of: http://code.activestate.com/recipes/474121/
"""
Created on Sep 24, 2013
@author: RandomHardcoreJerks
Requires pywin32
original: http://code.activestate.com/recipes/474121/
# HtmlClipboard
#Exchange 2010
Set-CASMailbox -Identity <user> -OwaEnabled $false
Set-CASMailbox -Identity <user> -EwsEnabled $false
Set-CASMailbox -Identity <user> -EcpEnabled $false
Set-CASMailbox -Identity <user> -MapiEnabled $false
Set-CASMailbox -Identity <user> -MapiBlockOutlookRpcHttp $true
Set-CASMailbox -Identity <user> -EwsAllowOutlook $false
@Erreinion
Erreinion / Hping3 Packet Grenade
Last active October 30, 2017 07:31
Firewall testing script using hping3
# Packet Grenade
# Feb 13, 2015
# Lists of targets
set pinglist [list www.google.com www.facebook.com]
set httplist [list www.google.com www.facebook.com]
set httpslist [list www.google.com www.facebook.com]
set ftplist [list]
set sshlist [list alt.org thebes.openshells.net]
@Erreinion
Erreinion / packet_grenade.py
Created March 9, 2015 21:21
Generate a variety of traffic types to various targets. Intended for firewall testing.
#! /usr/bin/env python
import sys
from os import path
import logging
# needed to remove warnings from scapy, even on import
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
@Erreinion
Erreinion / ldap_query_users.ps1
Created March 10, 2015 21:07
Powershell script to query LDAP (AD) for users. Accomplished without the ActiveDirectory plug-in from Quest.
# LDAP Query
# Look for all people. Excludes the DISABLED OU
$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.SearchRoot = 'LDAP://CN=Users,DC=example,DC=com'
$Searcher.Filter = '(&(objectCategory=person))'
$res = $Searcher.FindAll() | Sort-Object path
foreach ($usrTmp in $res)
{