r/usefulscripts • • Jan 14 '16

[PowerShell] Connect-ExchangeOnline

15 Upvotes

I'm sure many of us have written something similar, but I didn't see any posted when I searched. This is a short cmdlet to simplify connecting to Exchange Online for those of us on O365. It also includes a check parameter so you can quickly add a one liner to any other script working with Exchange cmdlets to see if the current session is already connected or not and offer to connect in case you've forgotten (I know I have).

http://pastebin.com/qthm29RG


r/usefulscripts • • Jan 14 '16

[CSV File] FCC Telemarketer and RoboCall Blacklist for Google Contacts 01/11/2016

Thumbnail
pastebin.com
15 Upvotes

r/usefulscripts • • Sep 22 '15

[POWERSHELL]All User Temp File Cleanup With Email Report

15 Upvotes

How this script works.

This script searches through the C:\Users Directory for all of the sub directories then creates a list of all of the users on the computer. It will then Delete all of the files from the temp file locations within the users directories. It also will delete temps from Windows and C:\Temp. The script checks disk usage before and after the script is run, and will then email a report.

http://pastebin.com/mh3sdwsw


r/usefulscripts • • Jan 31 '15

[BASH] Downloaders for pururin and fakku

15 Upvotes

i have written two version of each script, one that generates a list of URL in a text file, and, a more useful/automated one, creates a folder, makes a list then automatically downloads all the images and text file to the folder. (using curl instead of wget to read the list, as some *nix machines use curl instead of wget)

Fakku

Simple

To operate, after hitting enter, paste in part of the URL, like so

doujinshi/china-comi-english

or

manga/explicit-girlfriend-english

 #!/bin/bash
 read Media
 FILE=`echo ${Media} | sed 's/.*\///g'`
 curl -# "https://www.fakku.net/${Media}/read" | grep 'window.params.thumbs ='| tr '"' '\n' | grep fakku | sed 's/\\//g' | sed 's/^/https:/g'  | sed 's/thumbs/images/g' | sed 's/\.thumb//g' >> "${FILE}.txt"

Fakku

Automated (operated the same way)

   #!/bin/bash
   read Media
   FILE=`echo ${Media} | sed 's/.*\///g'`
   mkdir "${FILE}"
   cd "${FILE}"
   curl -# "https://www.fakku.net/${Media}/read" | grep 'window.params.thumbs ='| tr '"' '\n' | grep fakku | sed 's/\\//g' | sed 's/^/https:/g'  | sed 's/thumbs/images/g' | sed 's/\.thumb//g' >> "${FILE}.txt"
   linkNum=`cat ${FILE}.txt | wc -l`
   linkNum=$(( $linkNum + 1 ))
   n=1
   while [ $n != $linkNum ]
   do sed -n "$n{p;q;}" ${FILE}.txt | xargs curl --retry 8 -g -# -O; n=$(( $n + 1 ))
   done
   cd ..

Pururin

Simple

To operate, after hitting enter, paste in part of the URL, like so

16905/moshi-rito-darkness.html

or

6159/unlove-s.html

#!/bin/bash
read URL
SITE="http://pururin.com"
File=`echo ${URL} | sed 's/.*.\///g' | sed 's/\..*//g'`
curl -# "${SITE}/thumbs/${URL}" | grep '<li class="I0"' | tr '" ' '\n' | grep ^/view/ | awk -v Z=$SITE '{print 'Z' $0}' | tr '\n' ' ' | xargs curl -#  | grep '<img class="b" src="' | tr '"' '\n' | grep '/f/' | awk -v Z=$SITE '{print 'Z' $0}' >> "${File}.txt";

Pururin

Automated (operated the same way)

#!/bin/bash
read URL
SITE="http://pururin.com"
File=`echo ${URL} | sed 's/.*.\///g' | sed 's/\..*//g'`
mkdir "${File}"
cd "${File}"
curl -# "${SITE}/thumbs/${URL}" | grep '<li class="I0"' | tr '" ' '\n' | grep ^/view/ | awk -v Z=$SITE '{print 'Z' $0}' | tr '\n' ' ' | xargs curl -#  | grep '<img class="b" src="' | tr '"' '\n' | grep '/f/' | awk -v Z=$SITE '{print 'Z' $0}' >>"${File}.txt"
linkNum=`cat ${File}.txt | wc -l`
linkNum=$(( $linkNum + 1 ))
n=1
while [ $n != $linkNum ]
do sed -n "$n{p;q;}" ${File}.txt | xargs curl --retry 8 -g -# -O; n=$(( $n + 1 ))
done
cd ..

http://pastebin.com/Ertmp7uZ


r/usefulscripts • • Jan 10 '15

[POWERSHELL] Update XML files (and restart services) on remote computers

Thumbnail
brentsaltzman.com
15 Upvotes

r/usefulscripts • • Mar 18 '14

[bash]What security patches are available, email it to me (SUSE)

15 Upvotes

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" [email protected]

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 protected]"
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 • • Feb 26 '14

[BASH] mass: Send commands to large groups of servers in parallel.

Thumbnail
code.houstondad.com
15 Upvotes

r/usefulscripts • • Oct 08 '13

[PoSH] Kill-Java a Java Runtime Nuker conversion from batch to Powershell. Link and details inside.

15 Upvotes

This was a challenge set forth by /u/vocatus. Link to my github for the script Kill-Java.ps1. All are welcome to fork and contribute to any of the scripts.

It has never been tested, as it is still a work in progress, but the flow is sound. As per the Java Runtime Nuker. Got damn goto statements...

Todo list consists of building a test VM to get the logic and syntax settled for a working script.


r/usefulscripts • • Sep 11 '13

[BATCH] Simple script to perform basic repair tasks. Renew IP, flush DNS cache, gpupdate.

15 Upvotes

This is fairly simple script I just put together. Whilst I was on holiday the other week there were some DHCP issues - I created a split scope and then modified the scope, and it caused a few I.P conflicts. I fixed the problem remotely but obviously I couldn't renew the I.P addresses of the affected machines myself, so I had to call someone and ask them to go to each machine and run ipconfig /renew. Rebooting would also work but it can be quite impractical when people have lots of stuff open.

This script can be placed on the local drive, and you can tell users to run it if they're experiencing issues and you're not immediately available to help.

It requires a little input, but it should be easy enough for anyone to use. It will perform some basic functions (in the title) based on user input and the result of diagnostic commands, such as ping. As a last resort it'll reboot the computer.

If anything, you can use it to tried and rid some common support tickets...

http://pastebin.com/5KiMGAzW

Small error: line 95 should be "exit", not "end"


r/usefulscripts • • Nov 19 '12

[DOS BATCH] Open a new daily notes text file, date it. w/ Backup & Search.

15 Upvotes

This one is a very simple but useful script for me. I'm sharing it because it's DOS BATCH and not everyone is very batch file savvy (took me a bunch of Googling and tries).

Background: I take daily notes, and I want to keep them archived so they are on a cloud storage service (dropbox/Gdrive). I also need to occasionally dig through these files quickly for a certain fact or detail.

Here's the script DailyNotes.bat:

@echo off
Set mm=%DATE:~4,2%
Set dd=%DATE:~7,2%
Set yyyy=%DATE:~10,4%
if not exist %yyyy%-%mm%-%dd%.txt copy /b _sample %yyyy%-%mm%-%dd%.txt
start %yyyy%-%mm%-%dd%.txt
exit

Basically it sets the month, date, year in the syntax I'm looking for, then it creates a new file with the date as a name like today: 2012-11-19.txt, it creates it based off an empty file called "_sample", sometimes I change the contents of this to a template, if for example I have some important information to stay persistent across a week or something. Finally it opens the file by invoking the filename itself.

The nice thing is, if it does exist, as in I created it already that day, it will skip coping over the file and open the existing one directly.

Pretty basic but very useful for me. I then made a shortcut and set the attribute on the shortcut to minimize the command prompt that executes this. If there is a cleaner way to suppress the command prompt after the text editor is running that'd be wonderful. I haven't figured that out yet (help?). Props to user: hngovr for solving this in the comments!

As for indexing and search, I use AgentRansack: http://www.mythicsoft.com/page.aspx?page=download&type=agentransack

Hope you enjoy the basic script. I have some cooler ones to share but this is most recent!

Conversation: Does anyone handle this differently or better in their opinion, I'm always looking for good ideas!

Edit: Mods: Sorry about the prefix not matching the defined ones, there's nothing for [BATCH]...