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 • • 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 17 '17

[REQUEST] Powershell to check website availability, if not then perform action.

15 Upvotes

I have a script that runs to check for URL availability with a return code which works fine. However, the remediation aspect if it's NOT working has me a little confused.

Basically I'd like a simple statement that says "If this code is returned for more than 10 minutes, then restart X/Y/Z services on the server".

Any tips on how I would figure out the wait for 10 minutes, then do X process?


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 • • Apr 18 '17

[REQUEST][PowerShell] Help with excluding directories over a certain size

15 Upvotes

This is what I have so far. This script generates a MyDefrag file to put each game in it's own block so it defrags faster when updates happen and the files don't move around so much. (I have my performance sensitive games on an SSD).

What I'm looking to do is exclude directories under 1GB in that for loop so they don't get their own group. Ideas?

$all_game_dirs = Get-ChildItem -Directory -path D:\Games, D:\Games\Steam\Steamapps\Common, "D:\Games\Origin\Games", D:\Games\GOGGalaxyClient\Games, "D:\Games\Ubisoft Game Launcher\games" -exclude Steam, Desura, Origin, GOGGalaxyClient, "Ubisoft Game Launcher", Battle.net, "Blizzard App", "MWO Portal" | sort creationtime

ForEach ($game_dir in $all_game_dirs) { "SetVariable(Game,""$game_dir"")" | out-file $games_settings_file -append '!include System Defrag\Proc_Games!' | out-file $games_settings_file -append }


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!


r/usefulscripts • • Mar 16 '17

[REQUEST] A script to uninstall Network Printers on a remote Windows 7 Client

15 Upvotes

We've migrated from an old Win8kR2 Print Server to a Win12kR2 Print Server and I'd like to remotely remove all the install printers from the old print server on the (Win7) client machines on our network. I'm new to PowerShell (I'll be in Kindergarden soon!) and trying to write a script that will go out and remove those old installed printers, but ONLY for the old Printserver01 while leaving all the printers newly installed for Printserver02. I'm stuck with this syntax. How to I specify the print server and make this work?

$a = get-wmiobject -computername <servername> -query "SELECT * FROM win32_printer WHERE name = '<printername>'" $a.delete()


r/usefulscripts • • Jan 13 '17

[REQUEST] Get Windows license key in CMD / Batch (the solutions I've googled aren't working)

15 Upvotes

I understand this is probably not possible for Windows 8 and anything newer but if I can get it to work on 7 and Server 2008 that would be helpful.

I've tried googling for other solutions but pretty much every site is saying the same thing;

wmic path softwarelicensingservice get OA3xOriginalProductKey  

I always get "invalid query" on every OS I've tried it on. My intended use for this is to include it in a general information gathering script.

edit: Thank you for all the recommendations... I am aware of the many software solutions for this. Just looking for a way to incorporate this into a script as well.


r/usefulscripts • • Oct 21 '16

[REQUEST] Batch script to apply recent registry changes.

15 Upvotes

As it stands now, I have a batch file that runs every time a user logs on to edit their registry to change HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer so that their notifications bar is always shown.

The issue with this is that it does not apply immediately and requires that user to log out and then back in to apply. Is there a way in this batch file to apply this change immediately after running, or is it something my users are forced to deal with the first time they log in to a new machine?


r/usefulscripts • • Oct 21 '16

[REQUEST] Script to export DHCP scope pool ranges to a readable file.

15 Upvotes

I'm trying to export a list of the DHCP scope pool ranges on our 3 DHCP servers.

We have an application that I need to add the IP scopes into so it can scan certain IP ranges.

 

I've been searching for a way to script/automate this all morning but nothing is quite working. I was able to dump the contents of each server to a text file using netsh but that's not exactly what I need. I'd rather not go through the DHCP scopes one-by-one and copy down the IP ranges...

 

For what it's worth, I'm dealing with two different server OS's too.

  • 2x Windows Server SE 2003 SP2

  • 1x Windows Server Standard 2012 R2

 

Any ideas of what I could use?


r/usefulscripts • • Jun 20 '16

[Powershell] Setup services for a VDI environment

15 Upvotes

So we needed a script to set multiple services for VDI. I wanted something that I could scale for extension and safety. The script was generated from this Microsoft PDF https://download.microsoft.com/download/6/0/1/601D7797-A063-4FA7-A2E5-74519B57C2B4/Windows_8_VDI_Image_Client_Tuning_Guide.pdf titled Windows 8 Virtual Desktop Infrastructure image client tuning guide. The script is here http://pastebin.com/Kjss9e6K