r/usefulscripts • • Feb 26 '15

.Bat help please

16 Upvotes

Hello. I created a .bat, which will be shown below, to open multiple programs instead of having to click on each one individually. It was quick and easy and everything works, but I am having an issue with 2 of the programs. When the .Bat opens 1 of the programs it automatically creates an Options file on the desktop instead of using the one where the .exe is located. The second problem is similar. When it launches the program it does not pull the files from the directory but instead says they are missing and is going to place them on the desktop. Does anyone know why this would happen? Below you will find the code. With annotations next to the files causing problems.

@echo off

START "Spotify" "C:\Users\Michael\AppData\Roaming\Spotify\spotify.exe"

TIMEOUT 5 > NUL

START "Snip" "C:\Users\Michael\Desktop\Twitch\Overlay\Now PLaying\Snip\Snip.exe"

TIMEOUT 3 > NUL

START "" "C:\Program Files\OBS\OBS.exe"

TIMEOUT 3 > NUL

START "" "C:\Users\Michael\Desktop\Twitch\Spotify ad blocker\Blockify Lite 0.5.exe" This is the one that creates the options file

TIMEOUT 3 > NUL

START "" "C:\Users\Lacey\Desktop\Twitch\SubAlert\subalert.exe" This is the second program that adds directory files to the desktop

TIMEOUT 3 > NUL

Start "Twitch Dashboard" "http://www.twitch.tv/laceinyourspace/dashboard"

Timeout 5 > NUL

START "TWITCH ALERTS" "http://www.twitchalerts.com/dashboard/"

I greatly appreciate everyone help and time on trying to get this resolved.


r/usefulscripts • • Feb 02 '15

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

16 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 • • Dec 31 '14

[Bash] Simple file/directory rotation

16 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 • • Oct 10 '14

[BATCH] Notify when machine is online

16 Upvotes

I use this to find out when a user has arrived in their office and booted their machine. This is a re-post to comply with the new title guidelines.

@title ipDing
@echo off
    
%======<
This script continuously pings a specified IP or Computer Name
based on an INTERVAL (defined below in seconds).

While the machine is NOT replying, display timestamp of failure
in console window.

If IP Replies, display popup and play notification.
Popup will dismiss after 10 hours.

For sound to work, the program "playwav.exe" must be present
in the working directory.
>======%

setlocal enableextensions enabledelayedexpansion
set interval=600              %=<Interval between pings, in seconds>=%
set /p ipaddr= "Enter Machine Name Or IP: "
:loop
set state=down

for /f "tokens=5,7" %%a in ('ping -n 1 !ipaddr!') do (      
    if "x%%a"=="xReceived" if "x%%b"=="x1," set state=up
    ) %=<Perform single ping; if Received equals 1 then set state to UP>=%

if !state!==up (echo !ipaddr! Online > ipding 
msg /time:36000 %username% < ipding  %=<seconds before popup closes>=%
playwav "C:\Windows\Media\Windows Exclamation.wav"
del /q ipding
exit
)   
echo. > ipding
time /t >> ipding
echo. >> ipding
echo !ipaddr! Offline >> ipding
type ipding
del /q ipding
timeout /t !interval! /nobreak
goto :loop
endlocal

I used code from stackoverflow user "paxdiablo" to parse output from the PING command, referenced here: http://stackoverflow.com/questions/3050898/how-to-check-if-ping-responded-or-not-in-a-batch-file.

You will need to download the program "playwav.exe" (link) for the audio alert (ty saltinecracka)


r/usefulscripts • • Feb 25 '14

[BASH] A simple little script to run the same command on multiple ssh targets.

Thumbnail
pastebin.com
16 Upvotes

r/usefulscripts • • Sep 23 '13

[Powershell] Module for determining Windows Update Status and if Windows Update requested a reboot

Thumbnail
github.com
16 Upvotes

r/usefulscripts • • May 30 '13

[POWERSHELL] Reset user passwords with a GUI

16 Upvotes

This script looks up all enrolled students in a secondary college and populates a combo box with all of their usenames, it also populates three text boxes with their firstname, surname and their home group, these text boxes are refreshed whenever a new item is selected in the combobox

as of version 1 this script requires that you have RSAT installed as it relies on the ActiveDirectory powershell Module.

Unfortunately the script is currently over 11,000 characters so i cant post it to reddit directly however here is a pasebin link for those still interested.

Just a note on the Get-Students function i have done it this way to keep me from referencing absolute OU paths as we place students in OUs determined by their graduating year, so for example a Year 12 student(senior) would be this year so to determin the OU i used the variable

"$year12 = (get-date).year"

To grab their graduating year and then

"$year11 = $year12 + 1

$year10 = $year11 + 1

$year09 = $year10 + 1

$year08 = $year09 + 1

$year07 = $year08 + 1"

to determine the graduating years for the other year levels

http://pastebin.com/kucNNa2E

I am currently working on a search function using LDAP filters and i will update it when it is ready

EDIT 1 :i should also note that this relies on the users birthdate in the format "ddMMyyyy" being filled into an unused property in AD, i used the Fax field


r/usefulscripts • • Nov 15 '12

Please read the sidebar, and be as descriptive as possible with your submissions.

16 Upvotes

r/usefulscripts • • Jan 27 '26

[Rust] Dockyard, a snappy TUI for Docker container management.

15 Upvotes

Got pissed off that the first TUI I wrote (in Python) was too slow for my $5/m VPS instance so I ported it to Rust. Now it's fast.

Repo: https://github.com/905timur/dockyard


r/usefulscripts • • May 15 '25

[Combine PDFs with PowerShell, Anyone?]

15 Upvotes

Short answer, it can be done.

After hours of trying to figure out a free and automated way, I wanted to share back to the community. I really didn't know if I should put this in r/pdf or r/PowerShell or r/usefulscripts but here it goes. I figure it may help someone, somewhere, sometime.

My biggest challenge was that my situation didn't provide me the luxury of knowing how many files nor their names. I 100% controlled their location though, so I needed to create something generic for any situation.

I found a GREAT tool on GitHub: https://github.com/EvotecIT/PSWritePDF (credit and shoutout to EvotecIT) Instructions to install are there. I was getting hopeful, but the tool doesn't do a directory and you must know the names ahead of time. Bummer! But wait, PowerShell is powerful and it's kinda part of the name.....RIGHT?!? Well, yes, there is a way using PowerShell.

The syntax of the module is: Merge-PDF -InputFile File1, File2, File3, etc -OutputFile Output

If you have a simple job with lots of knowns, you could simply type in each file. But if you would like to automate the process at 2AM to combine all PDFs in a particular folder, you're going to need a script.

I'm sure given enough effort, I could have gotten this down to 1 line. LOL Feel free to roast my elementary PowerShell skills. Cheers!

$files = Get-ChildItem -Path C:\PDFs -Name
$files | %{$array += ($(if($array){", "}) + ('C:\PDFs\') + $_ )}
$OutputFile = "C:\PDFs\Combined.pdf"
$command = 'Merge-PDF -InputFile ' + $array + ' -OutputFile ' + $OutputFile
Invoke-Expression $command

r/usefulscripts • • May 04 '23

[Powershell] Powershell based CUCM User Device/License Manager tool

15 Upvotes

Hello all, was wanting to share a useful tool I created to solve an issue we were having with old user accounts in AD holding onto licenses in Cisco Unified Call Manager.

We have several environments where we have a pool of licenses that users utilize with Jabber and VOIP calling. A lot of users don't go into these environments often and end up getting their accounts disabled after a time period or are terminated and placed into a Disabled User OU in Active Directory.

This tool lists users that are disabled in AD, or who have not logged in for a given time period and then reaches out to the CUCM server via native Rest calls to CUCM's SOAP API to provide a list of the users found in AD that have a device assigned to them. You can then choose users in the list that you would like to remove the device from. Upon doing so the tool will remove and delete the devices associated with the selected user. This has the added benefit of cleaning up the license that user/device is holding in CUCM, freeing up your used licenses and possibly preventing having to ask your purchasing department to procure more licenses.

This specific functionality is pretty situation specific, but in the environments I manage we freed up roughly 600 used licenses being held by stale users across several environments, saving an estimated $30k/yr in additional license purchasing from Cisco. You can view the tool and source code here:
https://github.com/hillmanation/CUCM-Device-Manager

The tool requires no additional dependencies aside from (I assume) minimum PowerShell v5.0 and being run from a machine that has the Active Directory PowerShell module installed. It also opens up the possibility of more CUCM SOAP API calls and management utilizing the methods in this script to talk to the API with PowerShell.

Let me know what you all think and I hope this is able to help at least a few people with this very specific CUCM management issue.


r/usefulscripts • • Sep 04 '21

[QUESTION] batch scripting

15 Upvotes

how can i create for loop in batch script so that i can make outplut as : 1,2,3,4

with this for loop :

for /l %%i in (1,1,4) do echo %%i >> file.txt

the output in the text file is :

1

2

3

4

i want output in the text file as 1,2,3,4, i.e. in the same line separated by comma. is that possible?


r/usefulscripts • • Aug 06 '21

Automation Script. Willing to pay

15 Upvotes

Hey all.

Just wanting some help with a script if it's possible.

I'm wanting a script that can enable dhcp itself without any user input. It's going to be used to hopefully allow people to quickly fix an Internet connection problem.

So for the script. I'm needing a few criteria. Needs to be a batch file.

So this script will hopefully be able to detect all network adapters after running and store the names.

Then allow an option for the user to select the adapter. The script will then enable dhcp automatically.

I am willing to commission for this script.

Any help would be great

Thanks


r/usefulscripts • • Sep 07 '19

[AHK] Paste any Highlighted text to a new file.

15 Upvotes

I use this with Zim Wiki notes on Windows since the QuickNote functionality does not work here. Highlight any text, press the hotkey Win+V and it will paste to your "Inbox.txt" file.

I've put it in a Gist here: https://gist.github.com/victorfeight/2cc22e0fe57cd860a571517905f873d3


r/usefulscripts • • Jan 09 '18

[POWERSHELL] Automate calls against the Microsoft Graph by scripting the creation & consent of Azure AD Apps

15 Upvotes

It's a long title, but here's a script I've been working on for a few weeks now and have tested in a number of scenarios.

Automate API calls against the Microsoft Graph using PowerShell and Azure Active Directory Applications

This script will create and consent an Azure AD application that you can use to make API calls against the Microsoft Graph.

Using the Microsoft Graph, you can make calls and run reports that aren't available via the current PowerShell Modules.

In this example, the script retrieves the Office 365 Secure Score information via the beta reports endpoint and exports some of it's info to a CSV.

It also has a mechanism to consent calls that can only be run on behalf of a user (delegated permissions) by connecting to the Azure AD graph API and automating the manual consent step.

This is the single tenant version of the script, I'll post a script that will execute against all customer tenants tomorrow.

I also have versions of it that run against customer tenants and export the number of Office 365 activations, Skype for Business Users, Microsoft Teams Users etc. I can post these if there's any interest.


r/usefulscripts • • Nov 14 '17

[REQUEST] BackBlaze (personal) to Google Drive Business

15 Upvotes

I've done some initial research on this, but haven't seen anything too obvious yet.

I've spent the last 6 months or so backing up with BackBlaze and so far I'm just under halfway done (8TB). With my crappy ISP, I don't really have the resources to back up to both GDrive and BackBlaze, so I chose BackBlaze.

Is it possible to use a VPS (or something similar) as an intermediary to copy (or even sync) what is on BackBlaze to my unlimited Drive account?


r/usefulscripts • • Oct 11 '17

REQUEST - PS to enable Bitlocker

15 Upvotes

Hi Guys,

Just wondering if you could share your input on enabling Bitlocker through PS. Also wondering if people could correct or advise my cmdlets as I have been testing it and trying to get it to work as intended.

In short, I would like to: * Enable TMP with PIN at boot * Enable Bitlocker full drive encryption * Save the recovery key to a network path

The cmd I have used is

manage-bde -on c: | manage-bde -on c: -protectors -add c: -TPMAndPIN PINCODE -rp > "\SERVER\ME\DEVICE.txt"

To enable TMP at boot, it requires the Local Group policy enabled for "Required additional authentication at startup" So for this, I just imported the registry keys for it, but still shows as offline in group policy. Any advice on how to do this correctly?


r/usefulscripts • • Oct 04 '17

Batch File to Run BGINFO config. Detects Server 2003 and if 32/64 bit.

15 Upvotes

This is the script I came up with to deal with applying bginfo to my servers. I have to support a lot of old 2003 boxes and they don't like the vbs scripts I was using in my bgi config so I had to be able to detect them and apply a different bgi file. I have it setup to run in a global group policy that uses a WMI filter to only affect Servers and Domain Controllers.

@echo OFF


:CheckOS
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && (GOTO 32BIT) || (GOTO 64BIT)

:64bit
REM echo This is a 64bit operating system
ver | findstr /i "5\.2\."
if %ERRORLEVEL% EQU 0 (
REM echo OS = Server 2003
GOTO OLD
)
start \\filepath\bginfo64.exe \\filepath\wallpaper.bgi /timer:00 /nolicprompt /silent
GOTO END

:32bit
REM echo This is a 32bit operating system
REM Added If/Else to apply server 2003 Version thats missing vbs scripts
ver | findstr /i "5\.2\."
if %ERRORLEVEL% EQU 0 (
REM echo OS = Server 2003
GOTO OLD
)
start \\filepath\bginfo.exe \\filepath\wallpaper.bgi /timer:00 /nolicprompt /silent
GOTO END

:OLD
start \\filepath\bginfo.exe \\filepath\wallpaper2003.bgi /timer:00 /nolicprompt /silent
GOTO END

:END

r/usefulscripts • • Jul 11 '17

Name and Shame Hacking Attempts

Thumbnail
github.com
15 Upvotes

r/usefulscripts • • Jul 10 '17

[REQUEST] [POWERSHELL] Dynamic choice

15 Upvotes

hey,

trying to get a script running by providing a dynamic choice:

scenario:

  • have up to 10 IP's with http server

  • perform ping test or (New-Object System.Net.WebClient).DownloadFile to verify connectivity (same file on every server)

  • provide a dynamic list to the console based on the results (stating whether server is available or offline)

  • get user to choose one with read-host

  • have option to choose all, having all available server ip's in array

  • if option selected is not in list, or is offline go back to choice/verification

i'm a bit of a novice when it comes to powershell, so any help would be appreciated!


r/usefulscripts • • Jun 14 '17

[REQUEST][BATCH] Need a batch script to identify largest user Documents folder and copy it

15 Upvotes

Windows 7 & 10 - looking to have techs run a batch script with their elevated account that will identify the largest user Documents folder and copy it (and all subdirectories) to a temp directory for backup processes.


r/usefulscripts • • May 04 '17

[REQUEST] Append date and time to new files on Windows file server

15 Upvotes

So we purchased a new Konica printer that has a scanner. Users scan documents with specific part numbers as the file name. If abc.pdf exists, a user scans a new document as abc.pdf, the original is overwritten.

Our old Canon would make files abc(2).pdf, abc(3).pdf, etc.

I was thinking maybe some type of program/script that would watch the scan directories and append date, time (sec/millisecond) to ALL new files. I.e. abc_20170504091530.pdf.

Would like to do this on Windows 2012r2 file server.

Local printer company wants $3000 for software that would include overwrite protection.

Anyone have any ideas? Thanks!


r/usefulscripts • • Apr 26 '17

[REQUEST]Automatically join wireless networks on non-domain workstations - is there a better way?

15 Upvotes

We have a mix of about 20 Windows 7 and 10 workstations that are not on the domain, and get their internet from wifi. What I'm doing now to automate these machines joining wifi is using NETSH to export the wlan config to an XML file, and again using NETSH to import the XML file on the machines via local logon script.

Here's the kicker...we are going to start changing the wifi password about every 2 months.

Is there a way to modify my current process to also include updating the password when it changes? The ultimate goal is to not have to touch 20 workstations every time the wifi password is changed.

Any help is greatly appreciated!


r/usefulscripts • • Mar 20 '17

[REQUEST][BATCH][POWERSHELL] Looking to add more than one windows services in batch script that checks for them, can only either do one service or all services.

15 Upvotes

The script I am using is listed below:

sc query "AdobeARMservice" > ServiceListCount.csv

I want to add a second service (and later on, about 15 specific services total) "aspnet_state" to this script but I am having difficulty concatenating the services together.

I am open to any suggestions whether it's in batch, powershell or other windows-friendly languages because I plan using this script via Window's Task Scheduler to run on all of my machines.

Thank you!