Skip to content

Instantly share code, notes, and snippets.

@glallen01
glallen01 / pdfpw.bat
Created July 12, 2012 14:14
Windows batch script to password protect a directory of pdf files, storing the passwords in a csv file.
@ECHO OFF
setlocal EnableDelayedExpansion
md out
for /f %%G in ('dir /b "*.pdf"') do (
call:_pwgen passwd
pdftk %%G output out/%%G user_pw !passwd!
echo '%%G', '!passwd!' >> out/passwords.csv
)
#!/usr/bin/expect
set timeout 5
log_user 1
# Include your hosts in the hostlist
set hostlist "rt01 rt02 sw01 sw02"
foreach host $hostlist {
set prompt [append $host "#"]
spawn telnet $host
@glallen01
glallen01 / gist:5554334
Created May 10, 2013 13:18
Windows Server Management
# Requires PowerShell 2.0 and Server 2008-R2 or later.
import-module ActiveDirectory
get-module ActiveDirectory |
select-object -expandproperty ExportedCmdlets |
format-list value
New-PSDrive -PSProvider ActiveDirectory -Server 10.4.4.1 -GlobalCatalog -Root "" -Credential "domain\tim" -Name OtherAD
@glallen01
glallen01 / alt-script1.bat
Last active December 17, 2015 05:29
Create Domain Local And Global Groups, with nesting.
set DOMAIN=DC=Contoso,DC=COM
set FLAGS=-pwd "P@$$w0rd" -mustchpwd no -disabled yes
for /f "delims=" %%G IN (units.txt) do (
dsadd ou "OU=%%G,%DOMAIN%"
dsadd ou "OU=Users,OU=%%G,%DOMAIN%"
dsadd ou "OU=Computers,OU=%%G,%DOMAIN%"
dsadd group "CN=DL_%%G_WorkstationAdmin,OU=Users,OU=%%G,%DOMAIN%" -scope l
dsadd group "CN=GG_%%G_WorkstationAdmin,OU=Users,OU=%%G,%DOMAIN%" -scope g -memberof "CN=DL_%%G_WorkstationAdmin,OU=Users,OU=%%G,%DOMAIN%"
dsadd user "CN=%%G.Template,OU=Users,OU=%%G,%DOMAIN%"
(tool-bar-mode -1)
(require 'color-theme)
(color-theme-initialize)
(color-theme-clarity)
;(transient-mark-mode 1)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
@glallen01
glallen01 / reserve_dhcp.ps1
Created May 22, 2013 02:53
Create Multiple DHCP reservations with Powershell
$DHCPserver="172.16.32.2"
$DHCPscope="10.0.0.0"
$output="C:\netsh-out.cmd"
$csv=Import-CSV "MAC_LIST.csv"
# csv file MUST have the following header columns
# MAC,IP,NAME
# 12345678abcd,10.0.0.20,SITEWKCDR01
$csv | %{
@glallen01
glallen01 / gist:6437842
Created September 4, 2013 14:37
Windows Time Svc on First Forest Root Domain Controller
1. Log on to the first domain controller that you deployed.
2. At a command prompt, type the following command, and then press ENTER:
w32tm /stripchart /computer:<target> /samples:<number> /dataonly
3. Open User Datagram Protocol (UDP) port 123 for outgoing traffic, if needed.
4. Open UDP port 123 for incoming NTP traffic.
You can use a different port, if you prefer.
5. Type the following command to configure the PDC emulator, and then press ENTER:
w32tm /config /manualpeerlist:<peers> /syncfromflags:manual /reliable:yes /update
@glallen01
glallen01 / gist:6553636
Last active December 23, 2015 00:29
PowerShell Email
$smtp = new-object Net.Mail.SmtpClient("mail.example.com")
if( $Env:SmtpUseCredentials -eq "true" ) {
$credentials = new-object Net.NetworkCredential("username","password")
$smtp.Credentials = $credentials
}
$objMailMessage = New-Object System.Net.Mail.MailMessage
$objMailMessage.From = "script@mycompany.com"
$objMailMessage.To.Add("you@yourcompany.com")
$objMailMessage.Subject = "eMail subject Notification"
@glallen01
glallen01 / gist:7593320
Created November 22, 2013 01:35
python snmp example1
#!/usr/bin/env python
#Copyright (C) 2009 Allen Sanabria
#This program is free software; you can redistribute it and/or modify it under
#the terms of the GNU General Public License as published by the Free Software Foundation;
#either version 2 of the License, or (at your option) any later version.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details. You should have received a copy of i
@glallen01
glallen01 / userbackup.bat
Created January 12, 2014 21:37
user backup batch script
@ECHO OFF
SETLOCAL
SET _fileserver=\\file-server\user
SET _target=\\file-server\user\%USERNAME%
SET _source=%USERPROFILE%
SET _options=/MIR /MT /xA:T /XJ /A:N /R:1 /W:2
GOTO MENU1 :: choose robocopy runtime options
:JUMP1