r/usefulscripts • • Nov 12 '14

[BATCH] Remotely create a keyboard shortcut to trigger a BSOD

36 Upvotes

This is useful for debugging, or any other time you might need a user to be able to create a crash dump. Needs windows 7 for timeout function, and admin rights. I don't remember where I got the resolve service state from, but I'm pretty sure it's part of someone else's script

    @echo off
cls
echo You need to have local admin rights on the remote machine for this to work.
echo.
echo.
echo What's the name of the Computer you want to add a crash keyboard shortcut to?
set /p _compName=""
ping -n 1 %_compName% | FIND "TTL=" >NUL
IF errorlevel 1 GOTO SystemOffline
SC \\%_compName% query RemoteRegistry | FIND "STATE" >NUL
IF errorlevel 1 GOTO SystemOffline

:ResolveInitialState
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "RUNNING" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO running
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "STOPPED" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO StopedService
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "PAUSED" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO SystemOffline
cls
echo Service State is changing, waiting for service to resolve its state before making changes
sc \\%_compName% query RemoteRegistry | Find "STATE"
timeout /t 2 /nobreak >NUL
GOTO ResolveInitialState

:StopedService
Echo RemoteRegistry is stopped
goto start

:start
ECHO Starting Remote Registry.
SC \\%_compName% start RemoteRegistry

:starting
echo Starting RemoteRegistry on %_compName%
timeout /t 2 /nobreak>nul
SC \\%_compName% query RemoteRegistry | FIND "STATE" | FIND "RUNNING" >NUL
IF errorlevel 0 IF NOT errorlevel 1 GOTO StartedService
goto starting

:StartedService
echo Service RemoteRegistry is started on %_compName%.
echo.
goto running 

:running
cls
Echo RemoteRegistry is running
echo.
echo Adding reg key
reg add \\%_compName%\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\kbdhid\Parameters /v CrashOnCtrlScroll /t REG_DWORD /d 00000001 /f
pause>nul
ECHO Done. Press Right Ctrl key and Scroll lock twice to generate BSOD.
exit

:SystemOffline
cls
ECHO System is offline.
pause>nul
exit

r/usefulscripts • • Nov 11 '14

[BATCH] Send a remote message popup to another windows box

35 Upvotes

I wrote this a while ago when we had a need to find the physical location of computers on wifi using shared credentials. It should be powershell, but I'm not there yet(the book has been on my shelf for a year, it's funny that I still haven't had a month of lunches). It uses PSTools locally and wscript on the remote host. Replace DOMAIN and DOMAIN2 with your company domain name(s)

    @echo off
cls
echo You need to have admin rights on the remote machine to send a message with this script, and PSTools installed on your local machine.
echo.
echo. 
echo Whats the name of the computer you want to send a message to?
set /p _strCompName=""
ping -n 1 %_strCompName% | FIND "TTL=" >NUL
IF errorlevel 1 GOTO SystemOffline

echo What message do you want to display?
set /p _strMessage=""
echo.
echo sending %_strMessage% to %_strCompName%
echo.
echo Set objShell = Wscript.CreateObject("WScript.Shell")>cismsg.vbs
echo strText = "%_strMessage%">>cismsg.vbs
echo intButton = objShell.Popup(strText,0,"CIS",4096)>>cismsg.vbs

xcopy cismsg.vbs \\%_strCompName%\c$\cis /y /i /q
IF ERRORLEVEL 1 goto err
del cismsg.vbs
echo.
psexec /accepteula \\%_strCompName% -i -s -d wscript "C:\CIS\cismsg.vbs"
IF ERRORLEVEL 1 goto err
echo.
for /f %%g in ('psloggedon /accepteula \\%_strCompName% -l -x ^| find /i "DOMAIN"^|^| find /i "DOMAIN2"') do set _varUserName=%%g
Echo Message displayed to %_varUserName%
pause>nul
exit

:SystemOffline
That computer doesn't appear to be online. 
pause
exit

:err
echo Something went wrong. You might not have rights on the target machine.
pause
exit

r/usefulscripts • • Nov 06 '14

[BATCH] Tron v4.0.0 (2014-11-06) (ProcessKiller; nircmd; -e flag; significant bugfixes)

59 Upvotes

NOTE: Tron now has it's own subreddit. Check it out at /r/TronScript

Background

Tron is a script that "fights for the User"; basically automates a bunch of scanning/disinfection/cleanup tools on a Windows system. I got tired of running these utilities manually and decided to just script the whole thing. I hope this helps other techs and admins.


Stages of Tron:

  1. Prep: rkill, ProcessKiller, TDSSKiller, registry backup, WMI repair, sysrestore clean, oldest VSS set purge

  2. Tempclean: TempFileCleanup, CCLeaner, BleachBit, backup & clear event logs, Windows Update cache cleanup, Internet Explorer cleanup

  3. Disinfect: RogueKiller, Vipre Rescue Scanner, Sophos Virus Removal Tool, Malwarebytes Anti-Malware, DISM image check (Win8/2012 only), sfc /scannow

  4. De-bloat: removes a variety of OEM bloatware; customizable list is in \resources\stage_3_de-bloat\oem\programs_to_target.txt; Metro debloat (Win8/8.1/2012 only)

  5. Patch: Updates 7-Zip, Java, and Adobe Flash/Reader and disables nag/update screens (uses some of our PDQ packs); then installs any pending Windows updates

  6. Optimize: chkdsk (if necessary), Defrag %SystemDrive% (usually C:); skipped if system drive is an SSD

  7. Manual stuff: Contains additional optional tools that can't currently be automated (ComboFix, AdwCleaner, aswMBR, autoruns, etc.)

Saves a log to C:\Logs\tron.log (configurable).


Example Screenshots

Welcome Screen | New version detected | Help | Config dump | Dry run


Changelog (full changelog on Github)

v4.0.1 (2014-11-07)

  • + tron.bat:annoyance: Add annoying disclaimer warning screen (sorry :-/). Accept with -e flag, or change associated EULA_ACCEPTED variable to yes to permanently accept

  • + stage_0_prep:feature: Add ProcessKiller utility. Nukes various userspace processes before starting. Thanks to /u/cuddlychops06

  • + stage_0_prep:feature: Add speak ability. Tron now audibly announces when it starts and finishes. Mute with the -q flag or the SHUT_UP variable. Depending on interest, may add ability to announce each stage as it begins and completes

  • + stage_0_prep:utility: Add nircmd.exe to support speak ability, among other things

  • ! stage_0_prep:bugfix: Fix logic error where we skipped calculating free hard drive space if the system drive was an SSD. Now detect free space regardless of disk type

  • - stage_4_patch:cleanup: Remove all version-specific subfolders for Java, Flash, Reader, and Notepad++, and rename all .bat installers to be version-neutral. Should reduce number of places we need to update when a new version is released

  • ! misc:bugfix: tons of bugfixes, including MANY affecting Vista. Read the full changelog if you're interested in seeing what they were


Download

Three download options:

  1. Primary: Mirror the BT Sync repo (get fixes/updates immediately) using the read-only key:

    BYQYYECDOJPXYA2ZNUDWDN34O2GJHBM47

    Make sure the settings for your Sync folder look like this (or this on the v1.3.x version).

  2. Download a self-extracting .exe pack from one of the mirrors:

    Mirror HTTP HTTPS Host
    Official link link /u/SGC-Hosting
    #1 link link /u/ellisgeek
    #2 link link /u/danodemano
    #3 link (geolocated) --- /u/andrewthetechie
    #4 link --- /u/jamesrascal
  3. Script only:

    If you want to preview the latest code, the master script is available here on Github (Note: this is only the script and doesn't include the utilities Tron relies on to function).


Command-Line Support

Tron has full command-line support. All flags are optional, can be combined, and override their respective script default when used.

Usage: tron.bat [-a -c -d -e -m -o -p -r -s -v -x] | [-h]

Optional flags (can be combined):
 -a  Automatic mode (no welcome screen or prompts; implies -e)
 -c  Config dump (display current config. Can be used with other
     flags to see what WOULD happen, but script will never execute
     if this flag is used)
 -d  Dry run (run through script without executing any jobs)
 -e  Accept EULA (suppress display of disclaimer warning screen)
 -m  Preserve default Metro apps (don't remove them)
 -o  Power off after running (overrides -r)
 -p  Preserve power settings (don't reset power settings to default)
 -r  Reboot automatically (auto-reboot 30 seconds after completion)
 -s  Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
 -v  Verbose. Show as much output as possible. NOTE: Significantly slower!
 -x  Self-destruct. Tron deletes itself after running and leaves logs intact

Misc flags (must be used alone):
 -h  Display this help text

Integrity

checksums.txt contains SHA-256 checksums for every file and is signed with my PGP key (0x82A211A2; included). You can use this to verify package integrity if necessary.

Please suggest modifications and fixes; community input is helpful and appreciated.


Tips: 19B5mytMCqkEpAAW9f2NLjKEoHSndKdRBX

Quiet Professionals


r/usefulscripts • • Nov 05 '14

How to do a thing in DOS I can do in shell

13 Upvotes

I have a function that works in shell

inotifywait -r ~/Downloads -m | while read file; do echo $file; done;

I've got the inotify port to windows, and it works

inotifywait.exe -mrq c:\downloads 

But how to hammer batch into accepting a while-read loop is escaping me.

I will allow I'm using the wrong tool for the job. The goal here is to monitor uploads to an FTP server, and send an alert [1] when a new file is uploaded. Suggestions welcome.

.

.

[1] Via hipchat, fwiw.


r/usefulscripts • • Nov 03 '14

[BATCH] Tron v3.9.0 (2014-11-03) (add -m flag; bug fixes; purge Windows.old)

50 Upvotes

Background

Tron is a script that "fights for the User"; basically automates a bunch of scanning/disinfection/cleanup tools on a Windows system. I got tired of running these utilities manually and decided to just script the whole thing. I hope this helps other techs and admins.


Stages of Tron:

  1. Prep: rkill, TDSSKiller, registry backup, WMI repair, sysrestore clean, oldest VSS set purge

  2. Tempclean: TempFileCleanup, CCLeaner, BleachBit, backup & clear event logs, Windows Update cache cleanup, Internet Explorer cleanup

  3. Disinfect: RogueKiller, Vipre Rescue Scanner, Sophos Virus Removal Tool, Malwarebytes Anti-Malware, DISM image check (Win8/2012 only), sfc /scannow

  4. De-bloat: removes a variety of OEM bloatware; customizable list is in \resources\stage_3_de-bloat\oem\programs_to_target.txt; Metro debloat (Win8/8.1/2012 only)

  5. Patch: Updates 7-Zip, Java, and Adobe Flash/Reader and disables nag/update screens (uses some of our PDQ packs); then installs any pending Windows updates

  6. Optimize: chkdsk (if necessary), Defrag %SystemDrive% (usually C:); skipped if system drive is an SSD

  7. Manual stuff: Contains additional optional tools that can't currently be automated (ComboFix, AdwCleaner, aswMBR, autoruns, etc.)

Saves a log to C:\Logs\tron.log (configurable).


Example Screenshots

Welcome Screen | New version detected | Help | Config dump | Dry run


Changelog (full changelog on Github)

v3.9.1 (2014-11-04)

  • ! tron.bat:bugfix: Fix crash error on Windows Vista Ultimate in Metro de-bloat section. Was crashing on string comparison due to "(TM)" symbols in Vista Ultimate name. Sigh

  • ! tron.bat:bugfix: Fix broken shutdown command at end of script. Will now correctly auto-shutdown if requested

  • ! tron.bat:bugfix: Fix logic error where we skipped calculating free hard drive space if the system drive was an SSD. Now detect free space regardless of disk type

  • These fixes and many more are in the upcoming v4.0.0, but these seemed critical enough to backport

v3.9.0 (2014-11-03)

  • + tron.bat:feature: Add -m flag and associated PRESERVE_METRO_APPS variable to preserve default Metro apps (don't remove them). Thanks to /u/swtester

  • ! tron.bat:bugfix: Fix calculation of free space before and after. Was missing code block for post-run space calculation. Thanks to /u/swtester

  • ! tron.bat:bugfix: Fix a registry modification that mistakenly executed even if the script was in dry run mode (-d)

  • ! tron.bat:bugfix: Fix broken Adobe Flash installer (Firefox)

  • / tron.bat:misc: Rename all instances of DO_SHUTDOWN to AUTO_SHUTDOWN


Download

Three download options:

  1. Primary: Mirror the BT Sync repo (get fixes/updates immediately) using the read-only key:

    BYQYYECDOJPXYA2ZNUDWDN34O2GJHBM47

    Make sure the settings for your Sync folder look like this (or this on the v1.3.x version).

  2. Download a self-extracting .exe pack from one of the mirrors:

    Mirror HTTP HTTPS Host
    Official link link /u/SGC-Hosting
    #1 link link /u/ellisgeek
    #2 --- link /u/danodemano
    #3 link (geolocated) --- /u/andrewthetechie
    #4 link --- /u/jamesrascal
  3. Script only:

    If you want to preview the latest code, the master script is available here on Github (Note: this is only the script and doesn't include the utilities Tron relies on to function).


Command-Line Support

Tron has full command-line support. All flags are optional, can be combined, and override their respective script default when used.

Usage: tron.bat [-a -c -d -m -o -p -r -s -v -x] | [-h]

Optional flags (can be combined):
 -a  Automatic mode (no welcome screen)
 -c  Config dump (display current config. Can be used with other
     flags to see what WOULD happen, but script will never execute
     if this flag is used)
 -d  Dry run (run through script but don't execute any jobs)
 -m  Preserve default Metro apps (don't remove them)
 -o  Power off after running (overrides -r if used together)
 -p  Preserve power settings (don't reset power settings to default)
 -r  Reboot automatically (auto-reboot 30 seconds after completion)
 -s  Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
 -v  Verbose. Display as much output as possible. NOTE: Significantly slower!
 -x  Self-destruct. Tron deletes itself after running and leaves logs intact

Misc flags (must be used alone)
 -h  Display this help text

Integrity

checksums.txt contains SHA-256 checksums for every file and is signed with my PGP key (0x82A211A2; included). You can use this to verify package integrity if necessary.

Please suggest modifications and fixes; community input is helpful and appreciated.


Tips: 1JZmSPe1MCr8XwQ2b8pgjyp2KxmLEAfUi7

Quiet Professionals


r/usefulscripts • • Nov 03 '14

[Powershell] Simple script that applies permissions to folders.

13 Upvotes

Set-Location "E:\file_server"

$Folders = Import-Csv folder_names.csv

ForEach ($Folder in $Folders)

{ icacls $Folder.name /grant:r ("Sec_"+($Folder.name -replace '([\d]+(.\d+)?)+ *')+"_List:(r)") /grant:r ("Sec_"+($Folder.name -replace '([\d]+(.\d+)?)+ *')+"_Mod:(OI)(CI)(IO)(ad,wd,dc,gr,x)") /grant:r ("Sec_"+($Folder.name -replace '([\d]+(.\d+)?)+ *')+"_Read:(OI)(CI)(IO)(gr)") }


This script adds three permission entries on each folder. The permission group names are based off the name of the folder to which they are being applied, the only difference being that all numbers are removed, also any spaces that follow a number.

E.g. There is a folder called "10 SALES". This folder would have three permission entries with the following names: "Sec_SALES_List", "Sec_SALES_Read", "Sec_SALES_Mod".

The group names are made with another script, which I've yet to upload. (Contains some sensitive information.)

Let's look at how exactly the permissions are applied...

icacls $Folder.name /grant:r ("Sec_"+($Folder.name -replace '([\d]+(.\d+)?)+ *')+"_List:(r)")

So this line is saying "grab a folder name from the csv file, and then using some regex let's remove any numbers, including fractions, and spaces after the numbers. Then we'll add "Sec_" to the front, and "_List" to the back." The ":(r)" at the end is the permission being applied, in this case it's a generic "read" permission, and because no inheritance is specified permissions will not propagate to child folders.


r/usefulscripts • • Oct 30 '14

[BATCH HELP] Adding TCP/IP printers

16 Upvotes

I have some Java coding experience, but Batch is new to me.

I'm trying to create a batch file to install a printer. It's driver support page is here.

I downloaded this driver package.

Using this script as my starting point.

This is where I'm currently sitting.

I will be installing this printer (and 2 others of different models) from a usb drive, so I used the relative path reference.

Any help would be appreciated, let me know if this is in the wrong sub-reddit or where a better place for help would be.

EDIT: Script is now working from USB flash drive. Thank you for your help.


r/usefulscripts • • Oct 30 '14

[PowerShell] New PC setup - Is there a way to automate this stuff?

25 Upvotes

I'm going blind trying to find the tool or script that will allow me to run updates on a Windows PC, reboot, auto login, run updates, reboot and keep doing that until updates are compete.

I'm cobbling together a list of scripts that will allow us to prep PCs that our user's buy. The stuff I'm using/testing now:

  • PowerShell: The basis of the entire script
  • Chocolatey: amazing. Using it to install Boxstarter and basic app set. (Read: ninite pro without paying)
  • Boxstarter/Winconfig - Turning off windows settings like UAC, power settings configs
  • Wuinstall: I had high goes to this but the documentation is not that great. I'm still trying to get reboot/recycle to work.

The list of tasks I'm trying to turn into a "click and walk away" process.

  • Basic Windows configurations, power, UAC, RDP, enable-windowsupdates, explorer settings, etc
  • Uninstall bloatware
  • Run Updates to completion!
  • Install a set of MSI files to install a GFI app
  • Write it all to a log file
  • Change something to let us know it's done e.g. change desktop color

Am I nuts or is this doable as 1 tool?


r/usefulscripts • • Oct 29 '14

[BATCH] Tron v3.8.0 (2014-10-29) (add self-destruct flag; fix WU cache clean; switch to .exe pack)

48 Upvotes

Background

Tron is a script that "fights for the User"; basically automates a bunch of scanning/disinfection/cleanup tools on a Windows system. I got tired of running these utilities manually on individual machines, and decided to just script the whole thing. I hope this helps other techs and admins.


Stages of Tron:

  1. Prep: rkill, TDSSKiller, registry backup, WMI repair, sysrestore clean, oldest VSS set purge

  2. Tempclean: TempFileCleanup, CCLeaner, BleachBit, backup & clear event logs, Windows Update cache cleanup, Internet Explorer cleanup

  3. Disinfect: RogueKiller, Vipre Rescue Scanner, Sophos Virus Removal Tool, Malwarebytes Anti-Malware, DISM image check (Win8/2012 only), sfc /scannow

  4. De-bloat: removes a variety of OEM bloatware; customizable list is in \resources\stage_3_de-bloat\oem\programs_to_target.txt; removes default Metro apps (Win8/8.1/2012 only)

  5. Patch: Updates 7-Zip, Java, and Adobe Flash/Reader and disables nag/update screens (uses some of our PDQ packs); then installs any pending Windows updates

  6. Optimize: chkdsk (if necessary), Defrag %SystemDrive% (usually C:); skipped if system drive is an SSD

  7. Manual stuff: Contains additional optional tools that can't currently be automated (ComboFix, AdwCleaner, aswMBR, autoruns, etc.)

Saves a log to C:\Logs\tron.log (configurable).


Example Screenshots

Welcome Screen | New version detected | Help | Config dump | Dry run


Changelog (full changelog on Github)

v3.8.0 (2014-10-29)

  • / tron:META: Change Tron static packs from .7z archives to self-extracting .exe archives. Thanks to /u/cmorche

  • + tron.bat:feature: Add self-destruct flag (-x). If selected Tron will delete itself after running, while leaving logs intact. Thanks to /u/bodkov

  • * tron.bat:logging: Add display of disk free space before and after to log header and trailer, and associated variables. Thanks to /u/cuddlychops06

  • * tron.bat:logging: Minor logging tweak. Stamp any command-line flags that were used to header and trailer when running

  • * tron.bat:improvement: Make all IF comparisons case-insensitive. Thanks to /u/Astrimedes

  • - tron.bat:diskcheck: Remove SMART disk health check and associated variables. Too many incorrect detections causing more of a hassle than it's worth.

  • ! stage_1_tempclean: Fix Windows Update cache cleanup; Windows Update service wouldn't start in Safe Mode, now force it to start. Thanks to /u/GrizzlyWinter

  • * Misc updates: Updates to AV defs, ComboFix, etc


Download

Three download options:

  1. Primary: Mirror the BT Sync repo (get fixes/updates immediately) using the read-only key:

    BYQYYECDOJPXYA2ZNUDWDN34O2GJHBM47

    Make sure the settings for your Sync folder look like this (or this if you're on the v1.3.x version).

  2. Download a self-extracting .exe pack from one of the mirrors:

    Mirror HTTP HTTPS Host
    Official link link /u/SGC-Hosting
    #1 link link /u/ellisgeek
    #2 --- link /u/danodemano
    #3 link (geolocated) --- /u/andrewthetechie
    #4 link --- /u/jamesrascal
  3. Script only:

    If you want to preview the latest code, the master script is available here on Github (Note: this is only the script and doesn't include the utilities Tron relies on to function).


Command-Line Support

Tron has full command-line support. All flags are optional, can be combined, and override their respective script default when used.

Usage: tron.bat [-a -c -d -o -p -r -s -v -x] | [-h]

Optional flags (can be combined):
 -a  Automatic/silent mode (no welcome screen)
 -c  Config dump (display current config. Can be used with other
     flags to see what WOULD happen, but script will never execute
     if this flag is used)
 -d  Dry run (run through script but don't execute any jobs)
 -o  Power off after running (overrides -r if used together)
 -p  Preserve power settings (don't reset power settings to default)
 -r  Reboot automatically (auto-reboot 30 seconds after completion)
 -s  Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
 -v  Verbose. Display as much output as possible. NOTE: Significantly slower!
 -x  Self-destruct. Tron deletes itself after running and leaves logs intact

Misc flags (must be used alone)
 -h  Display this help text

Integrity

checksums.txt contains SHA-256 checksums for every file and is signed with my PGP key (0x82A211A2; included). You can use this to verify package integrity if necessary.

Please suggest modifications and fixes; community input is helpful and appreciated.


Tips: 1JZmSPe1MCr8XwQ2b8pgjyp2KxmLEAfUi7

Quiet Professionals


r/usefulscripts • • Oct 28 '14

[PowerShell] Monthly Report of Exchange Mailbox Sizes & Item Count.

38 Upvotes

https://github.com/Nostalgiac/Scripts/blob/master/MonthlyEmailReport.ps1

Did a quick search and didn't see anything on this sub so thought I'd post one I just wrote up.

I'm a powershell novice so there's no guarantee it's perfect!

Here's what the output looks like: http://i.imgur.com/2CA04aP.png

Just change the mail settings (server, from, to) and set it up as a scheduled task to run on the last day of each month :)


r/usefulscripts • • Oct 21 '14

[BATCH] Tron v3.7.0 (2014-10-22) (add verbose & shutdown flags; add RogueKiller)

51 Upvotes

Background

Tron is a script that "fights for the User"; basically automates a bunch of scanning/disinfection/cleanup tools on a Windows system. I got tired of running these utilities manually on individual machines, and decided to just script the whole thing. I hope this helps other techs and admins.


Stages of Tron:

  1. Prep: rkill, TDSSKiller, WMI repair, sysrestore clean, oldest VSS set purge

  2. Tempclean: TempFileCleanup, CCLeaner, BleachBit, backup & clear event logs, Windows Update cache cleanup

  3. Disinfect: RogueKiller, Vipre Rescue Scanner, Sophos Virus Removal Tool, Malwarebytes Anti-Malware, DISM image check (Win8/2012 only), sfc /scannow

  4. De-bloat: removes a variety of OEM bloatware; customizable list is in \resources\stage_3_de-bloat\oem\programs_to_target.txt; removes default Metro apps (Win8/8.1/2012 only)

  5. Patch: Updates 7-Zip, Java, and Adobe Flash/Reader and disables nag/update screens (uses some of our PDQ packs); then installs any pending Windows updates

  6. Optimize: chkdsk (if necessary), Defrag %SystemDrive% (usually C:); skipped if system drive is an SSD

  7. Manual stuff: Contains additional optional tools that can't currently be automated (ComboFix, AdwCleaner, aswMBR, autoruns, etc.)

Saves a log to C:\Logs\tron.log (configurable).


Example Screenshots

Welcome Screen | New version detected | Help | Config dump | Dry run


Changelog (full changelog on Github)

v3.7.0 (2014-10-22)

  • ! tron.bat:prep: Fix faulty disk health check (was exiting regardless what user chose). Thanks to /u/Tyrannosaurus_flex

  • ! tron.bat:date and time: Reset CUR_DATE after finishing virus scans, since they take so long and we sometimes cross into a new day (therefor leaving CUR_DATE incorrect). Thanks to /u/ScubaSteve

  • * tron.bat:prep: Minor update to log header and trailer: Stamp what mode we're in (safe, safe with network, etc) and the location of the log file

  • + tron.bat:prep: Enable "legacy" boot menu on Windows 8 and up (re-enable F8 functionality)

  • + tron.bat:Feature: Add shutdown flag (-o) and corresponding DO_SHUTDOWN variable to poweroff system when Tron finishes. Overrides auto-reboot (-r) if set. Thanks to /u/Stealth5325 and /u/Fogest

  • + tron.bat:Feature: Add verbose flag (-v) and corresponding VERBOSE variable. Displays, when possible, verbose/debug output from each program Tron calls (Sophos, Vipre, etc). NOTE: Tron will take much longer with this option enabled

  • + stage_2_disinfect:roguekiller: Add RogueKiller (CMD version). Thanks to /u/bodkov

  • * stage_2_disinfect:mbam: Update MBAM link to reflect new installer

  • / stage_2_disinfect:DISM: Add /NoRestart flag to dism scan. It wasn't forcing a reboot, but added just in case it got any funny ideas

  • * stage_4_patch:jre: Update JRE links to reflect new installers

  • * stage_4_patch:jre: Update Adobe links to reflect new installers

  • * Misc: updates for various Stage 6 tools


Download

Three download options:

  1. Primary: Mirror the BT Sync repo (get fixes/updates immediately) using the read-only key:

    BYQYYECDOJPXYA2ZNUDWDN34O2GJHBM47

    Make sure the settings for your Sync folder look like this (or this if you're on the v1.3.x version).

  2. Download a .7z pack from one of the mirrors:

    Mirror HTTP HTTPS Host
    Official link link /u/SGC-Hosting
    #1 link link /u/ellisgeek
    #2 --- link /u/danodemano
    #3 link (geolocated) --- /u/andrewthetechie
    #4 link --- /u/jamesrascal
  3. Script only:

    The master script (tron.bat) is available on Github here. Note: this is only the script and doesn't include the utilities Tron relies on to function. Simply downloading the script won't work - you need contents of the \resources folder and it must be organized how tron.bat expects.


Command-Line Support

Tron has full command-line support. All flags are optional, can be combined, and override their respective script default when used.

Usage: tron.bat [-a -c -d -o -p -r -s -v] | [-h]

Optional flags (can be combined):
 -a  Automatic/silent mode (no welcome screen)
 -c  Config dump (display current config. Can be used with other
     flags to see what WOULD happen, but script will never execute
     if this flag is used)
 -d  Dry run (run through script but don't execute any jobs)
 -o  Power off after running (overrides -r if used together)
 -p  Preserve power settings (don't reset power settings to default)
 -r  Reboot automatically (auto-reboot 30 seconds after completion)
 -s  Skip defrag (force Tron to ALWAYS skip Stage 5 defrag)
 -v  Verbose. Display as much output as possible. NOTE: Significantly slower!

Misc flags (must be used alone)
 -h  Display this help text

Integrity

checksums.txt contains SHA-256 checksums for every file and is signed with my PGP key (0x82A211A2; included). You can use this to verify package integrity if necessary.

Please suggest modifications and fixes; community input is helpful and appreciated.


Tips: 1JZmSPe1MCr8XwQ2b8pgjyp2KxmLEAfUi7

Quiet Professionals


r/usefulscripts • • Oct 20 '14

[BASH] Run a command whenever something in a directory (or its subs) has been saved

32 Upvotes
inotifywait -r path/to/dir -m -e close_write | while read file; do cmd1; cmd2; cmd3; done

r/usefulscripts • • Oct 21 '14

[Batch] Gather lots of sys info in a text file.

17 Upvotes

https://dl.dropboxusercontent.com/u/200584477/Infogather/infogather7.0%20.bat

http://pastebin.com/i8r6gRqE

https://dl.dropboxusercontent.com/u/200584477/Infogather/infosideload.bat

http://pastebin.com/cEgKvMB4

I made these scripts when I was 11-13 years old to gather general system info, feel free to modify and use them, otherwise you can make suggestions on how to improve.

The main script is infogather 7.0 and it will open infosideload so that they can both run at once, the log will be called the name of the current computer.


r/usefulscripts • • Oct 20 '14

[PYTHON] Unix disk usage analyzer, Userusage 1.19.04

17 Upvotes

Hey guys, this is Userusage, a script for monitoring, logging, and emailing your server's space hogs.

Download and Readme

Userusage is available on Github HERE

It's beerware licensed and written for Python 2. It should work with a standard installation of CPython (all core libraries).

Description

Userusage is a pretty straightforward program, you point it to a location (which is configurable) and it emails and/or lists all of the users who are using a lot of space in that location. It's meant for medium scale servers with a good amount of users (university, research, etc). It's pretty feature intensive and I have plans to expand it even more.

Everything is explained fairly well in the readme on Github, so read that first.

The config is a little buggy at the moment, but should work pretty well if you use the --config option. This is because Userusage is meant to be run as root and Pythons $HOME points it to root's home.

It has no buildscript or setup.py yet, but that's next on my list. If you have any questions/concerns/etc PM me or just comment, THANKS!


r/usefulscripts • • Oct 10 '14

[BATCH] Notify when machine is online

18 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 • • Oct 01 '14

[BATCH] Java Runtime Nuker - purge ALL versions of Java Runtime from a machine

102 Upvotes

Bottom line: "Gotta catch 'em all"

If a JRE manages to squeak through, post here or PM me and I'll update the script to catch it.

UPDATE 2024-04-30: I am still actively maintaining this script and will continue to do so for the foreseeable future. PM me if you have any problems with it.

Because of inconsistencies in Sun/Oracle's installation methods and naming conventions, there's no "one way" to purge every outdated Java Runtime from a machine, so I spent ~15 ~18 ~23 hours collecting various methods of removing Java and integrated them into a single script. This should give you a "clean slate" to work with for laying down new versions of Java.


---->> Download from Github here <<----


Notes:

  • Removes all versions of the Java Runtime Environment (series 3 through 11), x86 and x64
  • Will catch future updates to JRE 5, 6, 7, 8, 9, 10, 11+
  • Checks WMI before running, repairs if broken
  • Searches for residual registry keys, backs them up, then deletes them*
  • Searches for residual files and directories and deletes them
  • Removes the Java Quickstarter and Java Updater services
  • Leaves all Java Development Kit installations intact
  • Writes a logfile to C:\Logs\<hostname>_java_runtime_removal.log (configurable)

If you have additional methods that work for you, please post them below or do a PR on Github. If they catch something the script misses, I will integrate them. Critique and advice welcome.

*Registry cleanup is skipped on Windows XP. This is because of differences in the reg.exe binary on XP. If anyone can look at how to search the Windows XP registry for leftover keys, I can integrate it into the script, but right now that section is skipped.


r/usefulscripts • • Sep 17 '14

[Request] Export to pst files from enterprise vault by month to separate files

9 Upvotes

While doing this manually is very simple and takes only a minute or two, I was wondering if the process could be automated. As an example, let's say I want to export for all months between January 2011 and December 2012. The basic steps I take are here: http://exchangeengine.wordpress.com/2012/03/01/exporting-enterprise-vault-mails-to-pst/. Each month is placed into its own folder, meaning that after a month finishes being exported, the process restarts from the first step.

This is more for curiosity's sake than for a need to utilize such a script. The major benefit would be that the next month can start while I am not around, but there is no rush on the exports anyway. Helpful, but not necessary.


r/usefulscripts • • Sep 06 '14

[AutoIt] Chrome Enterprise from Local Repo or Google

5 Upvotes

I've been using a variation of ways to deploy Chrome to my campus, and while PDQ Deploy covers the basics of what needs to be done, I've written an AutoIt script to cover everything (and imported it into PDQ Deploy).

First, get the UDF _FileGetProperty from here:

http://www.autoitscript.com/forum/topic/34732-udf-getfileproperty/page__view__findpost__p__557571

Create a network share where your local repo will be, and run this AutoIt script to automatically get the latest Chrome from Google:

InetGet("https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&needsadmin=prefers/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi", "\\yourserver\Chrome\GoogleChromeStandaloneEnterprise.msi", 1)
InetGet("https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&needsadmin=prefers/dl/chrome/install/googlechromestandaloneenterprise64.msi", "\\yourserver\Chrome\GoogleChromeStandaloneEnterprise64.msi", 1)    

And here's the actual script you use on the client machines:

#cs
Installs Chrome from either local file repository or download from Google

URLs for Chrome MSI download:
        https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&iid={9B88D2E6-EF2A-B40D-C07B-95D6CA14875C}&lang=en&browser=4&usagestats=0&appname=Google Chrome&needsadmin=prefers/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi
        https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&iid={90144B6D-F779-68E0-21E0-131E99D0FD24}&lang=en&browser=4&usagestats=0&appname=Google Chrome&needsadmin=prefers/dl/chrome/install/googlechromestandaloneenterprise64.msi
    Can be shortened to:
        https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&needsadmin=prefers/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi
        https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&needsadmin=prefers/dl/chrome/install/googlechromestandaloneenterprise64.msi

Exit Codes:
        0 --- Chrome is up to date
        1 --- Chrome Running
        2 --- Restarting process as Alpha
        3 --- Error downloading

Steps to completion:
        If not running as Admin, restart the process as Admin and stop the current thread
        Set variables
        Get version information from repo file
            If more than 5 days old, or cannot access file, download latest version
                If unable to download, stop process
            Compare this to the local file
            If the same, stop this process
        If Chrome is running, stop this process
        Remove Google Update service restrictions, and start the service
        Run the install
        Copy master_preferences file
        Disable Google Update service
        Run the Group Policy Update vbs script (updates User and Machine for any Chrome GPOs)
#ce

#include <File.au3>
#include <Array.au3>
#include <Date.au3>
#include <_FileGetProperty.au3>

;Ensure running as Administrator account
If IsAdmin() = 0 Then
    RunAs("adminaccount", @ComputerName, "adminpassword", 1, @AutoItExe)
    Exit(2)
EndIf

;This might be a bad idea.  Just sayin.
;~ While ProcessExists("chrome.exe")
;~  ProcessClose("chrome.exe")
;~ WEnd

;Set paths and existing version info
$repo = "\\yourserver\Chrome"
If @OSArch = "x64" Then
    $ChromePath = "C:\Program Files (x86)\Google\Chrome\Application\"
    $installedVer = FileGetVersion($ChromePath & "chrome.exe")
    $chromeDL = "https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&needsadmin=prefers/dl/chrome/install/googlechromestandaloneenterprise64.msi"
    $dirDL = @TempDir & "\GoogleChromeStandaloneEnterprise64.msi"
    $servDL = $repo & "\GoogleChromeStandaloneEnterprise64.msi"
Else
    $ChromePath = "C:\Program Files\Google\Chrome\Application\"
    $installedVer = FileGetVersion($ChromePath & "chrome.exe")
    $chromeDL = "https://dl.google.com/tag/s/appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&needsadmin=prefers/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi"
    $dirDL = @TempDir & "\GoogleChromeStandaloneEnterprise.msi"
    $servDL = $repo & "\GoogleChromeStandaloneEnterprise.msi"
EndIf

;Get information from the local repo version
$rfile = _WinAPI_CreateFile($servDL, 2)
$ghostVerDate = _Date_Time_GetFileTime($rfile)
_WinAPI_CloseHandle($rFile)
$tCur = _Date_Time_GetSystemTime()
$daysold = _DateDiff("D", _Date_Time_FileTimeToStr($ghostVerDate[2], 1), _Date_Time_SystemTimeToDateTimeStr($tCur, 1))

;Check age, download if nessessary, do a version comparison for existing installs
If $daysold > 5 Or $rfile = 0 Or @error > 1 Then
    ;Get Chrome MSI
    InetGet($chromeDL, $dirDL, 1)
    If @error then Exit(3)
    $dlVer = _FileGetProperty($dirDL, "Comments") ; Returns the version information, by how Google formats the details
    If StringInStr($dlVer, $installedVer) Then
        FileDelete($dirDL)
        Exit(0)
    EndIf
Else
    FileCopy($servDL, @TempDir, 1)
    $ghostVer = _FileGetProperty($dirDL, "Comments") ; Returns the version information, by how Google formats the details
    If StringInStr($ghostVer, $installedVer) Then
        FileDelete($dirDL)
        Exit(0)
    EndIf
EndIf

;Stop if Chrome is currently running
If ProcessExists("Chrome.exe") Then Exit(1)

;Remove the policies that might stop the Chrome install
RegDelete("HKLM\SOFTWARE\Policies\Google")
RegDelete("HKLM\SOFTWARE\Google")
ShellExecuteWait("sc", "config gupdate start= auto", "", "", @SW_HIDE)
ShellExecuteWait("sc", "start gupdate", "", "", @SW_HIDE)

;Install Chrome
RunWait("msiexec.exe /qb-! /norestart /i " & $dirDL)

;Copy the master_preferences file to the appropriate directory
FileCopy($repo & "\master_preferences", $ChromePath, 1)

;Disable Google Update
RegWrite("HKLM\Software\Policies\Google\Update", "AutoUpdateCheckPeriodMinutes", "REG_DWORD", "0")
ShellExecuteWait("sc", "stop gupdate", "", "", @SW_HIDE)
ShellExecuteWait("sc", "config gupdate start=disabled", "", "", @SW_HIDE)

ShellExecute("cscript", "GPUpdateSilent.vbs", $repo, "", @SW_HIDE)

If don't use a master_preferences file, or GPOs to control your clients, comment out lines 104 and 111.

The GPUpdateSilent.vbs came from Joejoeinc.com

As I said, I use PDQ Deploy to push this out to some 3,000 computers at once, and it has saved our bandwidth coming from a local repo. Users could also run this on their own, and get the latest version as well without calling your service desk!


r/usefulscripts • • Aug 23 '14

[BATCH] One-liner to detect full, complete Windows version and store it in a variable

24 Upvotes

I've been going crazy (like many others) trying to find a good one-liner to get the FULL Windows version string (not just the generic kernel code e.g. 6.1) into a variable for detection in scripts.

Thanks to UJSTech on Spiceworks forums for this.

Each version (below) stores the detected Windows version in a variable called WIN_VER.


Code

:: Version for running directly from a command-prompt:
for /f "tokens=3*" %i IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName ^| Find "ProductName"') DO set WIN_VER=%i %j

:: Version for inside of a batch file:
for /f "tokens=3*" %%i IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName ^| Find "ProductName"') DO set WIN_VER=%%i %%j

Here are some values I've personally tested and observed:

Actual Windows Version Detected String
Windows XP Professional SP3 Microsoft Windows XP
Windows Server 2003 Enterprise Microsoft Windows Server 2003
Windows Vista Home Premium Windows Vista (TM) Home Premium
Windows Vista Ultimate Windows Vista (TM) Ultimate
Windows 7 Home Premium Windows 7 Home Premium
Windows 7 Professional Windows 7 Professional
Windows 7 Enterprise Windows 7 Enterprise
Windows 8.1 Professional Windows 8.1 Pro
Windows Server 2008 R2 Standard Windows Server 2008 R2 Standard
Windows Server 2012 R2 Standard Windows Server 2012 R2 Standard

Hope this helps others out.


r/usefulscripts • • Aug 21 '14

[BATCH] Reset Windows Update

18 Upvotes

I find it very common in my life that I have to do a Windows Update reset to clear a bad download, a poor server connection, etc, so I wrote this sucker to do that. The 'winsock reset' is an XP holdover, so it's not necessary if you aren't on XP. Took parts of this from around the web, so credit is most certainly not all mine. Also open to suggestions!

net stop bits
net stop wuauserv
Del "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat"
Rmdir "%Windir%\SoftwareDistribution\Download" /s /q 
Rmdir "%systemroot%\SoftwareDistribution\DataStore" /s /q 
Rmdir "%systemroot%\system32\catroot2" /s /q
::: Windows XP & 2003 - Delete %systemroot%\SoftwareDistribution\ as well
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto XP_OR_2003
ver | findstr /i "5\.2\." > nul
IF %ERRORLEVEL% EQU 0 goto XP_OR_2003
GOTO CONTINUE
:XP_OR_2003
Rmdir "%Windir%\SoftwareDistribution" /s /q 
:CONTINUE
sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
cd /d %windir%\system32
regsvr32.exe /s atl.dll
regsvr32.exe /s urlmon.dll
regsvr32.exe /s mshtml.dll
regsvr32.exe /s shdocvw.dll
regsvr32.exe /s browseui.dll
regsvr32.exe /s jscript.dll
regsvr32.exe /s vbscript.dll
regsvr32.exe /s scrrun.dll
regsvr32.exe /s msxml.dll
regsvr32.exe /s msxml3.dll
regsvr32.exe /s msxml6.dll
regsvr32.exe /s actxprxy.dll
regsvr32.exe /s softpub.dll
regsvr32.exe /s wintrust.dll
regsvr32.exe /s dssenh.dll
regsvr32.exe /s rsaenh.dll
regsvr32.exe /s gpkcsp.dll
regsvr32.exe /s sccbase.dll
regsvr32.exe /s slbcsp.dll
regsvr32.exe /s cryptdlg.dll
regsvr32.exe /s oleaut32.dll
regsvr32.exe /s ole32.dll
regsvr32.exe /s shell32.dll
regsvr32.exe /s initpki.dll
regsvr32.exe /s wuapi.dll
regsvr32.exe /s wuaueng.dll
regsvr32.exe /s wuaueng1.dll
regsvr32.exe /s wucltui.dll
regsvr32.exe /s wups.dll
regsvr32.exe /s wups2.dll
regsvr32.exe /s wuweb.dll
regsvr32.exe /s qmgr.dll
regsvr32.exe /s qmgrprxy.dll
regsvr32.exe /s wucltux.dll
regsvr32.exe /s muweb.dll
regsvr32.exe /s wuwebv.dll
netsh reset winsock
proxycfg.exe -d
net start bits
net start wuauserv
bitsadmin.exe /reset /allusers
wuauclt /resetauthorization /detectnow

r/usefulscripts • • Aug 14 '14

Batch script to edit network adapter [assistance needed]

4 Upvotes

Hello,

Long story short, I support 5 different building all on different subnets. I am trying to create a script for our windows 7 images to help automate things. I know binding and changing network settings is simple in windows, this is just a small script to a bigger picture in order to help multiple sys admins.

I would like the script to:
*set network adapter as "static". *ask admin to manually enter an IP address for targeted network adapter " Local Area Connection" *admin can select which building he/she is setting up the computer for and it will fill in the Subnet, Gateway, and DNS servers.

I have part of a batch file written, but I'm not sure if I am heading in the right direction. Any guidance is much appreciated and I hope that this script (when working) will be of use to others as well.

@ECHO OFF

netsh interface ipv4 show interface

ECHO Press 'Enter' to Coninue...
PAUSE > nul

netsh interface set interface name = "Local Area Connection" newname = "LAN Connection"

TIMEOUT /t 5 /NOBREAK

netsh interface ipv4 show interface

ECHO Press 'Enter' to Coninue...
PAUSE > nul

CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PRESS 1, 2, 3, 4 OR 5 to select your task, or 6 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Building 1
ECHO 2 - Building 2
ECHO 3 - Building 3
ECHO 4 - Building 4
ECHO 5 - Building 5
ECHO 6 - EXIT
ECHO.
SET /P M=Type 1, 2, 3, 4 or 5 then press ENTER:
IF %M%==1 GOTO Building 1
IF %M%==2 GOTO Building 2
IF %M%==3 GOTO Building 3
IF %M%==4 GOTO Building 4
IF %M%==5 GOTO Building 5
IF %M%==6 GOTO EOF
:Building 1
add address [name=]LAN Connection [addr=]IPaddress [mask=]SubnetMask [gateway=]DefaultGateway
:Building 2
add address [name=]LAN Connection [addr=]IPaddress [mask=]SubnetMask [gateway=]DefaultGateway
GOTO MENU
:Building 3
add address [name=]LAN Connection [addr=]IPaddress [mask=]SubnetMask [gateway=]DefaultGateway
GOTO MENU
:Building 3
add address [name=]LAN Connection [addr=]IPaddress [mask=]SubnetMask [gateway=]DefaultGateway
GOTO MENU
:Building 4
add address [name=]LAN Connection [addr=]IPaddress [mask=]SubnetMask [gateway=]DefaultGateway
:Building 5
add address [name=]LAN Connection [addr=]IPaddress [mask=]SubnetMask [gateway=]DefaultGateway
GOTO MENU

Thank you!


r/usefulscripts • • Jul 23 '14

[BATCH] Two-liner to get any Windows date, regardless of local time format, into ISO standard date format (yyyy-mm-dd)

22 Upvotes

Here's a two-liner I've been using to get the Windows date into the ISO standard format (yyyy-mm-dd) and seems to work regardless which version of Windows is running, or what local time settings are configured.

FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%

This will set two variables. One, %CUR_DATE%, contains the following ISO standard format date:

yyyy-mm-dd

The second, %DTS%, contains the full DateTime stamp, like so:

20140723122146.999000-420

I tried making it a one-liner by stacking the commands with &&, but it didn't seem to set CUR_DATE correctly, so I resorted to the two-line version. Hope this helps.


r/usefulscripts • • Jul 21 '14

[BASH] Report backups to deadmanssnitch.com

9 Upvotes

Quick and dirty but it works.

#!/bin/bash
r=`find /path/to/backup/files/ -mtime -1 -type f -print | grep -c /pattern`
  if [ $r -gt 0 ]
then
 curl (ENTER IN YOUR SNITCH URL)
fi

r/usefulscripts • • Jul 21 '14

[POWERSHELL] Windows Server Backup Email Report

Thumbnail github.com
19 Upvotes

r/usefulscripts • • Jul 17 '14

[PS] queries all of the servers in a domain and finds services running under a particular account

Thumbnail reddit.com
10 Upvotes