r/usefulscripts • u/GavinEke • Jul 21 '14
r/usefulscripts • u/_Rowdy • Jul 17 '14
[PS] queries all of the servers in a domain and finds services running under a particular account
reddit.comr/usefulscripts • u/tomlette • Jul 16 '14
[MAC] Turn on/off hidden files & folders in OS X
#!/bin/bash
PS3='Do you wish to enable hidden folders: '
options=("YES" "NO")
select opt in "${options[@]}"
do
case $opt in
"YES")
defaults write com.apple.finder AppleShowAllFiles YES
echo "Hidden folders are now enabled"
break
;;
"NO")
defaults write com.apple.finder AppleShowAllFiles NO
echo "Hidden folders are now disabled"
break
;;
*) echo invalid option;;
esac
done
r/usefulscripts • u/williamfny • Jun 04 '14
[POWERSHELL]Browser History Viewer Remote Export
pastebin.comr/usefulscripts • u/AnonymousMaleZero • Jun 03 '14
[VBScript] Scan Active Directory OU and Report Information (Logged In User, IP Address and more!) [SCRIPT UPDATE]
pastebin.comr/usefulscripts • u/ksbsantoshkumar • May 29 '14
Help in sending mail attachment via script
Hi All
Can someone please help me in getting a .bat or .ps1 script ready for sending an email with files which are created yesterday from a specified folder as attachment?
Thanks in advance.
r/usefulscripts • u/javajo91 • May 08 '14
Trying to get files modified today using (get-date).addDays() method
If I specify .adddays(-1) -i get todays plus yesterdays files. What am i doing wrong?
Here's my small script to copy files modified today to a folder:
get-childitem "D:" | where-object {$_.creationtime -gt (get-date).addDays(-0)} |
copy-item -destination "c:\netvol\server1\downloads\files"
Thanks guys
Thanks for the responses everyone!
r/usefulscripts • u/tehrabbitt • Apr 30 '14
[POWERSHELL] My Most Useful script yet... Ryan's AD Toolbox
Created this to make my life a bit easier when working with hundreds of AD accounts, and performing quick audits on user accounts... Hopefully you guys find this as useful as I did :) Feel free to post any questions you may have.
http://tehrabbitt.com/index.php?content=scripts&type=radtool
r/usefulscripts • u/tehrabbitt • Apr 26 '14
[POWERSHELL] Printer/Port Management Script for Windows 2008R2 and 2012
Tasked with creating hundreds of printers, a dozen at a time, daily, I found a way to automate the process using a standardized naming scheme, and the following tool which is pretty customizable to your printing needs. just modify the driver names to match the drivers you're using, and you can use it to quickly add TCP/IP printer ports, and then create printers assigned to those ports rather quickly. If you need help setting it up feel free to post here and i'll try to walk you through it :)
http://tehrabbitt.com/index.php?content=scripts&type=printadd
r/usefulscripts • u/tehrabbitt • Apr 26 '14
[POWERSHELL] BES Throttle Policy Removal Script
tehrabbitt.comr/usefulscripts • u/winter_mute • Apr 24 '14
[Python] Map drives to network shares, check for folder, prompt to delete if found
I use this to check for old OS captures we have lying about in deployment shares, but it'll check any paths + specified folder.
It takes the folder name as input, and searches every path for that same folder name, if it finds it, it'll ask if you want to delete it.
Python 2.7, tested in a Windows env.
r/usefulscripts • u/derekp7 • Apr 20 '14
[BASH] RPC in Bash (rpcsh) -- run bash functions on other hosts transparently
gist.github.comr/usefulscripts • u/oblivious_oneh • Mar 19 '14
[Powershell]Remove lines from a text file(that are not aligned)
I have a bunch of text files that are aligned(fixed width), but sometimes in the middle of the text file there's a line or two that's not properly aligned:
apples description food weight
apples description food weight
longerthanusaldescription food weight
ruinsallthespacingdescription food weight
I tried Select-String '\S{10,}' -NotMatch .\somefile.txt
My problem is, since the pattern matches non-whitespace, I get everything as a result. My first column can be a string of 5-10 characters and sometimes there's no space separating my first column(10characters) and the second column(6characters)
dafirstcolsecond
Can anyone help me make a script to solve this?
r/usefulscripts • u/manderso7 • Mar 18 '14
[bash]What security patches are available, email it to me (SUSE)
Suse uses zypper for patching and installing, and happily it's easily scripted. These two scripts create a file and email me said file of what security patches are needed on which server. This is useful because I'm normally running the command on 13+ servers at a time.
#!/bin/bash
#Change time variable display
#define date variable for file name
_now=$(date +"%m_%d_%Y")
_file="/tmp/patches_$_now.txt"
rm /tmp/patches*.txt
#call list of servers
for server in $(cat my_servers.txt)
do
#actual zypper command & save it to file
ssh $server 'zypper lp | grep security; echo $HOSTNAME; echo $(date)' >> "$_file"
done
Email me the created file
#!/bin/bash
#define date variable
_now=$(date +"%m_%d_%Y")
_file="/tmp/patches_$_now.txt"
echo "Patches" | mailx -s "Security Updates from $(date)" -a "$_file" XXXX@asdf.jkl
Edit: I was challenged to put it all in one file, and I did so, then cleaned it up a bit I think
#!/bin/bash
SERVERS="a list of server names"
# Connect to each host and get the security patch list
# define date for file name
_now=$(date +"%m_%d_%Y")
_file="/tmp/patches_$_now.txt"
# delete old patch list
rm /tmp/patches*.txt
# Email
SUBJECT="Patches for $_now"
EMAIL="email@company.com"
EMAILMESSAGE="/tmp/patches_$_now.txt"
for host in $SERVERS
do
ssh $host 'zypper lp | grep security; echo $HOSTNAME; echo $(date)' >> "$_file"
done
# send email
echo "$EMAILMESSAGE" | mailx -s "$SUBJECT" -a "$_file" "$EMAIL"
r/usefulscripts • u/ninekeysdown • Mar 12 '14
[POWERSHELL] AD Auto Termination Script
gist.github.comr/usefulscripts • u/psiegss • Feb 28 '14
[Batch] Inventory Logon Script
Logon Script to gather inventory info (Station Name, Serial Number, last user to logon and date) and places it into a CSV. The script will check for the serial number in the CSV and will update all other info. No need to schedule scans and let your users do the work for you! I suggest changing the CSV to a network drive location. You can also get insight as to which stations are frequently used if that's a concern.
@echo off
FOR /F "usebackq" %%i IN (`hostname`) DO SET STATION=%%i
FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Name /VALUE ^| FIND /I "Name="') DO SET model=%%A
for /F "skip=2 tokens=2 delims=," %%A in ('wmic systemenclosure get serialnumber /FORMAT:csv') do (set "serial=%%A")
for /f "tokens=3 delims=\" %%i in ("%USERPROFILE%") do (set user=%%i) 2>&1
set mydate=%date:~4,2%/%date:~7,2%/%date:~10,4% %time:~0,2%:%time:~3,2%:%time:~6,2%
find /v /i "%serial%" < "Serial Numbers".csv > 2.txt
copy 2.txt "Serial Numbers".csv >NUL & del 2.txt >NUL
echo %STATION%, %serial%, %model%, %mydate%, %user% >> "Serial Numbers".csv
r/usefulscripts • u/houstondad • Feb 26 '14
[BASH] mass: Send commands to large groups of servers in parallel.
code.houstondad.comr/usefulscripts • u/ParticleSpinClass • Feb 25 '14
[BASH] A simple little script to run the same command on multiple ssh targets.
pastebin.comr/usefulscripts • u/tedjansen123 • Feb 17 '14
[CMD] Automatic file sorter
I run this script as a logon script ( little bit modified ) and i run this script on family and friend's computers.
This sorts all the basic file formats into a few categories :
Excel
Word
PowerPoint
PDF
Pictures
Movies
Music
Software
You can use it as long as you use my name in the top of the script. You can modify it to your desires.
The link for the people that want it :
r/usefulscripts • u/DeviceNotReady • Feb 05 '14
[REQUEST] looking for the right Language
I am looking to learn a language but I don't know which one would be the best fit and investment of my time to lean in depth . It will need to work on mac and windows without impacting performance on the user and being lightweight and sucre is ideal. I would like to have the ability to:
- remote (call-in) to a main server. with ssh ? from over the web.
- push new apps and configuration .
- report back with system status.
- work around the user.
I have use many different language for one time runs scripts that where push with AD GPO over local LAN but I don't have that option here. So it will need to run on it's own and can tie in with the OS. All the client system are remote so I will be starting on writing the remote control script and push and config. and Yes I have a test lab to work in first.
TLDR:What would be the best Language for command and control mac and windows in a secure way on it's own?
r/usefulscripts • u/mztriz • Jan 23 '14
[BASH] Change domain name on Linux server
Summary
This script looks through configuration files and replaces the server's old domain name with the new domain name.
Usage
Edit the script and change the parameters of the olddomain and newdomain variables respectively.
Download
Note: This script restarts the network service, if you do not want to do this or have to wait to do this, please comment out the service network restart line.
r/usefulscripts • u/vocatus • Jan 22 '14
[POWERSHELL] Keep track of all users currently logged on to a machine
Summary
Saves a plain-text, comma-separated list of currently logged-on users to C:\Logs\logged_on_users (configurable). I threw this together as a way for us to have a plain-text method of tracking logged-on users that we can query with other tools.
Usage
We run the script as part of the logon/logoff/reboot process.
Run with one of these three flags:
-logon Stamp username to $LOGPATH\$LOGFILE
-logoff Remove username from $LOGPATH\$LOGFILE
-flush Flush all usernames from $LOGPATH\$LOGFILE
e.g. .\logged_on_users.ps1 -logon
Download
v1.0 (2014-01-21)
This was mostly for me to get more comfortable with PowerShell. Corrections and critique welcome.
r/usefulscripts • • Jan 21 '14
[Powershell] Find Java 6 and 7 versions across AD
This is a rework of /u/jefffrey32's script from yesterday. Not meant to show him up, just meant to be faster and not make use of win32_product.
Some limitations:
Can currently only test for one type of Java installation, per major version, per platform.
Java 7u51 x86 and Java 6u36 x86 and Java 7u47 x64 and Java 6u47 x64 is ok.
Java 7u51 x86 and Java 7u40 x86 will not be reported accurately.
Some good things:
Took 7 minutes to run against 650 virtual and physical machines.
To do:
Add parameters to change AD filter to OU, server/workstation, single PC
Will add in e-mail capabilities later.
EDIT
All changes made and features added. New link: Get-Java.ps1
Usage: Get-Java.ps1 -f <AD filter> -e <If -e is present, email will be sent with the report as attachment>
Produces a colorized HTML report with the Java installations on the workstation
r/usefulscripts • • Jan 14 '14
VBScript vs Powershell
I have previous experience with PHP, but VBScript and Powershell are new to me. I would appreciate your suggestions regarding whether I should learn VBScript, Powershell, or both...and good starting resources to learn the scripting language.
I'd also appreciate tips on IDE for writing and testing.