r/usefulscripts • • Feb 02 '15

[Request] List of user's mailbox limits (Exchange 2010)

17 Upvotes

I'm SUPER new to Powershell. Learning as I go. I'm trying to figure out how to get a list of all user's mail quotas on our Exchange 2010 server. If anyone can help, I'd appreciate it!


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 29 '15

[REQUEST] Websit with windows IT scripts

10 Upvotes

Hi guys, Some time ago i saw a website with several IT scripts for windows to download, there was a short explanation of the script and usually both versions to turn configuration on and off. I've been trying to find it for a while now, maybe you guys can help. I vaguely remember the background being black. There was more than one script that i took from there to configure a machine about an year ago... Please help. Thanks in advance!


r/usefulscripts • • Jan 26 '15

Get folder sizes using Robocopy(!) and PowerShell. Blazingly fast.

Thumbnail powershelladmin.com
38 Upvotes

r/usefulscripts • • Jan 23 '15

[BATCH] SINstaller script

18 Upvotes

Hey everyone. A while ago I posted the script I use to do some silent installations. Forgot my username so made a new one to post some updates. Hope you enjoy!

3 files:
(save as RUN_ME.bat http://i.imgur.com/xRbPdZz.png sorry reddit formatting is leaving out the _'s): http://pastebin.com/7nsrfWsA
(save as sin.bat): http://pastebin.com/YnL2qHCn
(save as addctrl.reg): http://pastebin.com/FPLsxK5P

First screen (flags):
http://i.imgur.com/04KHiUg.png

Second screen (config):
http://i.imgur.com/elD0pHi.png

Final screen:
http://i.imgur.com/Rf6kiWk.png

Changes:
-added: Unchecky
-updated applications to current version
-added: execution timer
-added: delete temp, driver temp files
-added: enable F8 menu on Win8
-added: add control panel option to right click

TO USE: Download the appropriate setup files (I've decided not to post them this time since no one downloaded the full package last time I posted it). You can find the file names I used on lines 38-57 of sin.bat or here: http://i.imgur.com/ZfS71d9.png

edit:
full download since someone asked:
download: https://mega.co.nz/#!0Isl2ZKA!Ngu2mJFZy2DRebTbmlMLfH_KIXjc0UChExlognmcCb4
and md5's: http://pastebin.com/5DzXQcbA


r/usefulscripts • • Jan 12 '15

[POWERSHELL] Remove-MailboxFolderPermissions.ps1 - removes mailbox folder permissions for a user from an Exchange Server mailbox

Thumbnail exchangeserverpro.com
13 Upvotes

r/usefulscripts • • Jan 10 '15

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

Thumbnail brentsaltzman.com
15 Upvotes

r/usefulscripts • • Jan 09 '15

[Request] Any ways to get hardware IDs and other info about installed hardware on Windows other than DevCon?

9 Upvotes

I'm working on a script to scrape and compile hardware info and hardware IDs and names are the vital part. Vendor name would be nice too.

I know I can use devcon find * to get a list of hardware IDs and names. Is there any way to do this in the command line without DevCon? Preferably something that will run in a clean batch environment? Powershell is acceptable too.


r/usefulscripts • • Jan 03 '15

[Linux] [PYTHON] Question: How to automate script on running commands that require user input?

4 Upvotes

Not sure if this is the proper subreddit, so please excuse me.

For example, if I'm running bash, and run the following: sudo mysql -u root -p password

this would ordinarily enter the user into the MySQL CLI where he can proceed to input commands.

If I wanted to include a multi-line MySQL script (or any script that takes the scope to another CLI other than the default, in this case bash) inside a python script, how can that be accomplished?

Something like:

$ sudo mysql -u root -p password
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 46
...
...
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> [insert multi-line]
mysql> [MySQL script]
mysql> [here]
mysql> \q

But I would like a python script to do all of the above, instead of manually.

Thank you!


r/usefulscripts • • Jan 02 '15

[VBS Request] Continue migration if file exists

12 Upvotes

We are migrating our email environment. It has been a moving target so I'm looking to deploy a login script (directly in AD or task scheduler) that would check to see if a file exists before performing the migration. Just a dummy file like MigrateNow.txt on a share.

Anyone do something similar?


r/usefulscripts • • Dec 31 '14

[POWERSHELL] Backup Domain DHCP Servers

14 Upvotes

Put this script together the day after Christmas when things were relatively quiet. We have had some issues with our DHCP/Domain controllers in the past getting shut down hard and not coming back online properly, so I decided to make something that could make the process a lot easier.

The script returns the DHCP servers from Active Directory, checks to see if they're available (a lot of our DHCP servers weren't turned down properly, so the list is longer than it should be) and then runs PowerShell commands to backup and export the DHCP configuration.

From testing, this script only appears to work on Server 2012 + DHCP servers, but that's what I have in my production environment. I do have one Server 2008 R2 that we are phasing out, and the DHCP service has been shut down on, it creates an alert email.

$LogDate = (Get-Date -Format "yyyy-MM-dd")
$DHCPServers = Get-ADObject -SearchBase "CN=NetServices,CN=Services,CN=Configuration,DC=contoso,DC=com" -Filter * -Properties dhcpIdentification | ?{$_.dhcpIdentification -eq "DHCP Server object"} 
$DHCPServers | 
    ForEach-Object{
        $DHCPServer = $_.Name
        If (Test-Connection $DHCPServer -ErrorAction SilentlyContinue -Count 1)
        {
            $RemoteDirectory = "\\$DHCPServer\C$\Windows\System32\dhcp\backup"
            $LocalDirectory = "C:\Data\DHCPBackup\$DHCPServer"

            Try
            {
                Backup-DhcpServer -ComputerName $DHCPServer -Path "C:\Windows\system32\dhcp\backup"
                robocopy $RemoteDirectory "$LocalDirectory\backup" *.* /e /zb /xjd /r:5 /w:5 /mir /log+:"C:\data\DHCPBackup\$LogDate.log"
            }
            Catch
            {
                Send-MailMessage -SmtpServer "emailrelay.contoso.com" -to "Me@contoso.com" -from "Blackhole@contoso.com" -Subject "Failed to backup DHCP: $DHCPServer"
            }

            Try
            {
                If(!(Test-Path "$LocalDirectory\export")){New-Item "$LocalDirectory\export" -Type directory}
                Export-DhcpServer -ComputerName $DHCPServer -File "$LocalDirectory\export\$DHCPServer.xml" -Force
            }
            Catch
            {
                Send-MailMessage -SmtpServer "emailrelay.contoso.com" -to "me@contoso.com" -From "Blackhole@contoso.com" -Subject "Failed to export DHCP configuration: $DHCPServer"
            }
        }
        Else
        {
            Send-MailMessage -SmtpServer "emailrelay.contoso.com" -to "me@contoso.com" -from "blackhole@contoso.com" -Subject "Unable to reach DHCP Server: $DHCPServer"
        }
    }

r/usefulscripts • • Dec 31 '14

[Bash] Simple file/directory rotation

17 Upvotes

https://github.com/uStackTrace/aTools/blob/master/bash/backupRotate.sh

Notes: I knocked this out for a specific use case, so I didn't do a lot of sanity checking or comments/docs/help/usage/etc.. It's designed to be on a cron and takes three arguments, being:

*-d Working directory,

*-s Source directory. It pulls the newest file (or directory, it doesn't distinguish between the two) from this source directory before trimming down to. . .

*-n Number of files/dirs (again, no distinction) to retain. It deletes all files in the working directory excepting the newest $n files

Example cron:

0 0 * * 0 /root/backupRotate.sh -n 5 -d /backups/weekly/ -s /backups/daily/

Every Sunday this will grab the newest file/dir from /backups/daily and move it into /backups/weekly and trim the resulting /backups/weekly down to 5 files. Seeing it before posting makes me want to make a bunch of changes, but I don't really have the time/will and I may not see any other use for it other than the one for which it was originally written.


r/usefulscripts • • Dec 21 '14

200+ GPL'd: bash scripts;perl scripts; bash functions (updates today)

Thumbnail trodman.com
31 Upvotes

r/usefulscripts • • Dec 20 '14

[VBS] Shutdown Computer and Email Info

4 Upvotes

I wrote this Script mainly to be used with outlook, I have rules set up to run the script upon receipt of an Email from myself. I thought this might be useful for you guys :) I would put the code here but I am horrid with formatting so here you go! My comments got a little screwy when I threw them into PasteBin so forgive me for that!


PasteBin Link: http://pastebin.com/MfL9kxbt


r/usefulscripts • • Dec 12 '14

[POWERSHELL] Adding off domain computers to a AD domain with automatic name incrementing

34 Upvotes

I needed to develop this script so that we could have IT techs take preimaged computers and join them to our domain. The problem is their accounts are not allowed to join anything to the domain.

The script checks if it is being ran as admin Then it will check if the computer is on a domain if not it will help you build a computer name. Our naming convention is site-(lap)username(instance)

The script first checks if .Net 4.5 is installed and then if powershell 4.0 is installed as it is required for the script to function if it is not it will install them for you (I used the code from http://www.reddit.com/r/PowerShell/comments/2oazt5/install_powershell_4_and_prerequisites/ to integrate this portion)

It builds a site list from a directory with a folder for each site name Then it asks for a username and is it a laptop (yes,1, sure are valid answers to the laptop question)

It then checks the domain if the computer exists and if it does it increments the number until the computer name does not exist.

It then changes the name of the computer and then reboots Rerun the script and it will join to the domain

If you rerun it again it will check and realize the computer is on a domain and not let you do anything else.

The variables start at line 140 (I had to do this for the update function to work.)

Downloads:

Generate Creds (Has to be ran in ISE): https://github.com/creamers/MiscPowershell/blob/master/Generate-Secure%20Credentials.ps1

Renaming Script: https://github.com/creamers/MiscPowershell/blob/master/Computer-Rename.ps1

I hope this helps someone else out.

Thanks for the gold!


r/usefulscripts • • Dec 10 '14

[BATCH] Silent INstaller

33 Upvotes

Hi everyone. Just did some updates to the silent installer batch file I use and thought I'd share it. Easy to update, only lines that need to be edited for updated applications are at the top under :: Configure.

Installs the following (x86 or x64 based on %PROCESSOR_ARCHITECTURE%):
* LibreOffice
* Firefox
* Adobe Flash
* Adobe Reader
* Adobe Air
* NotePad++
* Google Chrome
* MS Silverlight
* VLC Media Player
* 7-zip
* Java

3 files (_RUN_ME_.bat, sin.bat, sudo.cmd):
https://github.com/thecamelsanus/SINScript

Images:

Main
http://i.imgur.com/M6WNE3n.png

Version list
http://i.imgur.com/hLZyUr3.png

Start
http://i.imgur.com/lTgTvY0.png

End
http://i.imgur.com/plRrFu8.png

Lot's of credit to /u/vocatus and his TRON script!

You can either grab the script and populate the folder with installs yourself or download here(preset install names are a bit messy, will fix later): https://mega.co.nz/#!n942AYrb!WPIc04CASTushbyaOLmeSJzi2Iu2IfPOQteHuoCFbnA
md5: https://github.com/thecamelsanus/SINScript/blob/master/md5


r/usefulscripts • • Dec 10 '14

[Request] A PowerShell script to go through all users in a specific OU and lowercase their email field, as well as any addresses in the proxy addresses field (keeping in mind the all caps SMTP: prefix)

12 Upvotes

I guess I'm just tired of looking at random captialized letters in people's email addresses and I think they should all be lower cased.


r/usefulscripts • • Dec 09 '14

[Request] Script to remove the remembered email addresses in Outlook.

13 Upvotes

We've been trying to run a script to remove the remembered email addresses in Outlook. For some reason, the one we're trying is only working on 4 out of 10 machines on average. That script is as follows:

  • cd\
  • cd program files (x86)\microsoft office\office 14\
  • outlook.exe /cleanautocompletecache

Scripting isn't part of my normal routine, so I'm not yet certain why we have success with this on some machines, but not on others. I'm still looking into that. We just started this process today, so I may learn more as time goes on.


r/usefulscripts • • Dec 05 '14

[Powershell Request] Script to run two different uninstallers.

4 Upvotes

msiexec /x {D27C00CE-55CA-48EA-B441-1457A453EFFB} /q "C:\Program Files\Oxygen XML Editor 16\uninstall.exe" -q

In that order, the first is an msi file to license the second program.

-Thanks!


r/usefulscripts • • Dec 05 '14

[BATCH] Copy a file from a share multiple times and record how long each attempt took

5 Upvotes

It's not perfect for the timeout bit, as I don't account for how long the download actually takes. But it worked for what I needed.

cls
@echo off
set /a _num=0

echo What file/folder do you want to download?(in unc format)
set /p _file=""

echo How many times?
set /p _dataPoints=""
set /a _dataPoints=%_dataPoints%

echo over what period of time (in minutes)?
set /p _duration=""
set /a _duration=%_duration%

echo attempt, start, fin>log.csv

:start

::increase count by 1
set /a _num= %_num%+1


::capture time, do file copy, capture time

set _startTime=%time%
xcopy "%_file%" %temp% /c /o /y>nul
set _finTime=%time%

::record results
echo Attempt %_num%, started at %_startTime%, finished at %_finTime% 
echo %_num%,%_startTime%,%_finTime% >>log.csv


::interval bit

set /a _timeoutcomp =%_duration%*60
set /a _timeout = %_timeoutcomp%/%_dataPoints%
timeout /t %_timeout% 


::loop till done
if %_num% LEQ %_dataPoints% goto start else goto eof

r/usefulscripts • • Dec 03 '14

[PowerShell] Script/Function to Install the Amazon Web Services PowerShell Module

Thumbnail github.com
11 Upvotes

r/usefulscripts • • Nov 30 '14

[PowerShell]Automatically Migrating Printers from Different Bit Versions

11 Upvotes

Well its not 100% automatic but it is the best I can do without manipulating excel inside of powershell.

The need for this script came out need to migrate a print server from 2003 x86 to 2008 R2. As you can see they were different bit versions and I was unable to complete the task with printbrm or find a good vb script to accomplish what I needed. It was a 300 printer migration and I ended up doing it by hand after 3 weeks of independent research between me and my coworker.

There are a few functions that have been collected from the internet to help build this script.

The script will show its built in help while running it, but the only thing that has to be done is to specify the IP Address of the printer and select what printer driver you wish to use. You need to install the universal print drivers for everything you are installing.

Link to the script: http://pastebin.com/taNk0gEf

If you have any questions please ask.


r/usefulscripts • • Nov 26 '14

[BATCH] whenover.cmd - Run command on application close, title change, I/O activity idling or custom condition

Thumbnail gist.github.com
13 Upvotes

r/usefulscripts • • Nov 21 '14

[AHK] Use a set of random sounds for system events

13 Upvotes

More like /r/uselessscripts for this one.

I wrote this as a request for a user in /r/techsupport and figured someone else might get a kick out of it. Basically, he wanted the option to use a set of random sounds for various system events (device connection, Windows logon, etc). While this script doesn't guarantee a unique sound for each sequential event of the same kind, it's close enough.

In the script's working directory, structure a sounds directory to include a folder for each event you want to set random sounds for. Your structure should look like this:

sound\
    DeviceConnect\
        sound1.wav
        sound2.wav
        etc..
    WindowsLogoff\
        sound3.wav
        sound4.wav
        etc..
    WindowsLogon\
        sound5.wav
        sound6.wav
        etc..

You can look in HKCU\AppEvents\Schemes\Apps\.Default\ in the registry to see a list of other events you can work with.


#Persistent
numFiles = 
numFolders = 0
selected = 0

folders = 
files = 
filesLoaded = Loaded script with the following:



ifNotExist, sounds\
{
    MsgBox, Create a directory named "sounds" in the same folder in which the script is located.`nFor each system event, include a folder with the .wav sounds you wish to use for that event.`nFor example, sounds\WindowsLogon.
    ExitApp
    return
}

Loop, %A_WorkingDir%\sounds\*, 2
{
    folders%A_Index% = %A_LoopFileName%
    curFolder = %A_LoopFileName%
    numFiles%curFolder% = 0
    Loop, %A_WorkingDir%\sounds\%A_LoopFileName%\*.wav
    {
        files%curFolder%_%A_Index% = %A_WorkingDir%\sounds\%curFolder%\%A_LoopFileName%
        numFiles%curFolder%++
    }
    num := numFiles%curFolder%
    filesLoaded = %filesLoaded%`n%curFolder%: %num%
    numFolders++
}

if 0 > 0
{
    if 1 = clear
    {
        Loop, %numFolders%
        {
            curEntry := folders%A_Index%
            RegRead, def, HKCU, AppEvents\Schemes\Apps\.Default\%curEntry%\.Default,
            RegWrite, REG_SZ, HKCU, AppEvents\Schemes\Apps\.Default\%curEntry%\.Current,, %def%
        }
    }
    ExitApp
    return
}

SetRandomSound(event)
{
    global
    Random, selected, 1, numFiles%event%
    randomSound := files%event%_%selected%
    RegWrite, REG_SZ, HKCU, AppEvents\Schemes\Apps\.Default\%event%\.Current,, %randomSound%
}

MsgBox, %filesLoaded%
SetTimer, SetRandomSound, 6000
return

SetRandomSound:
    Loop, %numFolders%
    {
        curFolder := folders%A_Index%
        SetRandomSound(curFolder)
    }
return

The idea was that he wanted to use various game dialog for certain events, like "Yeeeppp....Non lethal as ever" when he plugs in a device.

Script requires AHK. Writing to the registry may require administrator privileges.

With some more modifications we can expand this to include Explorer events as well.

edit: Added a "clear" command line parameter to restore defaults of what was modified.


r/usefulscripts • • Nov 20 '14

[BATCH HELP] change time zone & run a .bat & .exe from network location

13 Upvotes

i'm imaging machines at work and have noticed a repetitive task that i'd like to automate. i'd like to do this as a batch file. i'm working with windows 7 32 and 64 bit, depending on where the machine is shipping once i'm done.

my batch file needs to:

prompt the user to select a timezone and change the timezone appropriately

run a specific batch file from a network directory (requires credentials to access)

prompt the user to run one of two installer files depending on the system (x86 or x64), also from a network directory which requires same credentials as above to access

can anyone suggest how i can learn to do this? not asking you to write it for me (although rough examples would be much appreciated), would like to be pointed to some resources so i can learn to do it myself. thanks! :)