r/usefulscripts • • Jul 20 '16

[PowerShell] Shadow RDS Session Script for Helpdesk Staff

Thumbnail
github.com
17 Upvotes

r/usefulscripts • • Jun 17 '16

[BASH] Create a script exiting task that will trigger even if script fails or is killed - such as deleting a lock file or moving a log.

17 Upvotes

This trick is handy if you have a process that runs in the background and depends on a lock file or other means of indicating it is running, or you have any other exiting task required regardless of how script is closed. For instance a log needs moved or a file that informs other tasks that the script is still "running". This will allow you to clean up after the script exits even if it fails or is killed before getting to the "cleanup" part of the script.

Just add this at the beginning of your script and a background process will start that will monitor the status of your script and performing an action once it is no longer running.

(while kill -0 $$ &> /dev/null ; do
      sleep 1
done
[exit task here])&

Edit: Fixed formatting.


r/usefulscripts • • Apr 07 '16

[REQUEST]Change AD home folder

17 Upvotes

We're in the process of migrating servers at my company, and we need to change everyone's Home folder in AD....

Currently everyone's Home Folder is G:, which connects to \XX01\users$[logon] - What we need to do is change that home folder to \XX02\users$[logon] for everyone in our office...

I can do it manually, but that would take hours since we have 100+ people. Is there a powershell script that will do that much faster?

Thank you


r/usefulscripts • • Nov 30 '15

[CSV File] FCC Telemarketer and RoboCall Blacklist for Google Contacts (11/30/2015)

Thumbnail
pastebin.com
17 Upvotes

r/usefulscripts • • Jul 22 '15

[POWERSHELL] Generate the list of antivirus exclusions for Exchange Server 2013 servers

Thumbnail
exchangeserverpro.com
17 Upvotes

r/usefulscripts • • Oct 30 '14

[BATCH HELP] Adding TCP/IP printers

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

[CMD] Automatic file sorter

17 Upvotes

I run this script as a logon script ( little bit modified ) and i run this script on family and friend's computers.

This sorts all the basic file formats into a few categories :

  • Excel

  • Word

  • PowerPoint

  • PDF

  • Pictures

  • Movies

  • Music

  • Software

You can use it as long as you use my name in the top of the script. You can modify it to your desires.

The link for the people that want it :

http://pastebin.com/cz2cMBNG


r/usefulscripts • • Nov 29 '12

[BATCH] Windows Differential Backup Script

17 Upvotes

This script creates a rolling differential backup set using 7-Zip. Edit the script to set your variables (backup destination, source, staging area, etc) and run as a scheduled job no more than once per day.

Download

v1.5.2 (2015-11-03)

  • + Merge :log function from Tron; convert most echo commands to use log function

v1.4.7 (2013-03-01)

Output of help (-h) flag


C:\> backup_differential.bat -h

  backup_differential.bat v1.5.0

  Usage: backup_differential.bat < -f | -d | -r | -a | -c [days] >

  Flags:
   -f:  create a full backup
   -d:  create a differential backup (requires an existing full backup)
   -r:  restore from a backup (extracts to P:\backup_staging\backup_restore)
   -a:  archive the current backup set. This will:
          1. move all .7z files located in:
             \\thebrain\backup_vocatus\Everything else\backups\personal\root
             into a dated archive folder.
          2. purge (delete) all copies in the staging area (P:\backup_staging)
   -c:  clean (AKA delete/purge) archived backup sets from staging and long-term storage.
        Optionally specify number of days to run automatically. Be careful with this!
        Note that this requires a previously-archived backup set (-a option)
   -s:  show job options (show what parameters the script WOULD execute with)

  Edit this script before running it to specify your source, destination, and work directories.

Output of current settings (-s) flag


  C:\> backup_differential.bat -s

   Current configuration:

    Script Version:       1.5.0
    Source:               C:\Users\vocatus\root
    Destination:          \\coolServer\backup_vocatus\personal\root
    Staging area:         P:\backup_staging
    Exclusions file:      C:\Users\vocatus\root\Scripts\sysadmin\backup_differential_excludes.txt
    Backup prefix:        backup
    Restores unpacked to: P:\backup_staging\backup_restore
    Log file:             C:\Logs\FIREWALKER_backup_differential.log
    Log max size:         2097152 bytes
  
   Edit this script with a text editor to customize these options.

r/usefulscripts • • Jun 04 '25

[PowerShell] Enhanced Dashboards with PSWriteHTML – Introducing InfoCards and Density Options

16 Upvotes

For those using PSWriteHTML, here's a short blog post about New-HTMLInfoCard and updates to New-HTMLSection in so you can enhance your HTML reports in #PowerShell

This new 2 features allow for better elements hendling especially for different screen sizes (New-HTMLSection -Density option), and then New-HTMLInfoCard offers a single line of code to generate nicely looking cards with summary for your data.

Here's one of the examples:

New-HTML {
    New-HTMLHeader {
        New-HTMLSection -Invisible {
            New-HTMLPanel -Invisible {
                New-HTMLImage -Source 'https://evotec.pl/wp-content/uploads/2015/05/Logo-evotec-012.png' -UrlLink 'https://evotec.pl/' -AlternativeText 'My other text' -Class 'otehr' -Width '50%'
            }
            New-HTMLPanel -Invisible {
                New-HTMLImage -Source 'https://evotec.pl/wp-content/uploads/2015/05/Logo-evotec-012.png' -UrlLink 'https://evotec.pl/' -AlternativeText 'My other text' -Width '20%'
            } -AlignContentText right
        }
        New-HTMLPanel {
            New-HTMLText -Text "Report generated on ", (New-HTMLDate -InputDate (Get-Date)) -Color None, Blue -FontSize 10, 10
            New-HTMLText -Text "Report generated on ", (New-HTMLDate -InputDate (Get-Date -Year 2022)) -Color None, Blue -FontSize 10, 10
            New-HTMLText -Text "Report generated on ", (New-HTMLDate -InputDate (Get-Date -Year 2022) -DoNotIncludeFromNow) -Color None, Blue -FontSize 10, 10
            New-HTMLText -Text "Report generated on ", (New-HTMLDate -InputDate (Get-Date -Year 2024 -Month 11)) -Color None, Blue -FontSize 10, 10
        } -Invisible -AlignContentText right
    }
    New-HTMLSectionStyle -BorderRadius 0px -HeaderBackGroundColor '#0078d4'

    # Feature highlights section - now with ResponsiveWrap
    New-HTMLSection -Density Dense {
        # Identity Protection
        New-HTMLInfoCard -Title "Identity Protection" -Subtitle "View risky users, risky workload identities, and risky sign-ins in your tenant." -Icon "🛡️" -IconColor "#0078d4" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px -BackgroundColor Azure

        # # Access reviews
        New-HTMLInfoCard -Title "Access reviews" -Subtitle "Make sure only the right people have continued access." -Icon "👥" -IconColor "#0078d4" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px -BackgroundColor Salmon

        # # Authentication methods
        New-HTMLInfoCard -Title "Authentication methods" -Subtitle "Configure your users in the authentication methods policy to enable passwordless authentication." -Icon "🔑" -IconColor "#0078d4" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px -ShadowColor Salmon

        # # Microsoft Entra Domain Services
        New-HTMLInfoCard -Title "Microsoft Entra Domain Services" -Subtitle "Lift-and-shift legacy applications running on-premises into Azure." -Icon "🔷" -IconColor "#0078d4" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

        # # Tenant restrictions
        New-HTMLInfoCard -Title "Tenant restrictions" -Subtitle "Specify the list of tenants that their users are permitted to access." -Icon "🚫" -IconColor "#dc3545" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

        # # Entra Permissions Management
        New-HTMLInfoCard -Title "Entra Permissions Management" -Subtitle "Continuous protection of your critical cloud resources from accidental misuse and malicious exploitation of permissions." -Icon "📁" -IconColor "#198754" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

        # # Privileged Identity Management
        New-HTMLInfoCard -Title "Privileged Identity Management" -Subtitle "Manage, control, and monitor access to important resources in your organization." -Icon "💎" -IconColor "#6f42c1" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

        # Conditional Access
        New-HTMLInfoCard -Title "Conditional Access" -Subtitle "Control user access based on Conditional Access policy to bring signals together, to make decisions, and enforce organizational policies." -Icon "🔒" -IconColor "#0078d4" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

        # Conditional Access
        New-HTMLInfoCard -Title "Conditional Access" -Subtitle "Control user access based on Conditional Access policy to bring signals together, to make decisions, and enforce organizational policies." -IconSolid running -IconColor RedBerry -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px
    }


    # Additional services section
    New-HTMLSection -HeaderText 'Additional Services' {
        New-HTMLSection -Density Spacious {
            # Try Microsoft Entra admin center
            New-HTMLInfoCard -Title "Try Microsoft Entra admin center" -Subtitle "Secure your identity environment with Microsoft Entra ID, permissions management and more." -Icon "🔧" -IconColor "#0078d4" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

            # User Profile Card
            New-HTMLInfoCard -Title "Przemysław Klys" -Subtitle "e6a8f1cf-0874-4323-a12f-2bf51bb6dfdd | Global Administrator and 2 other roles" -Icon "👤" -IconColor "#6c757d" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

            # Secure Score
            New-HTMLInfoCard -Title "Secure Score for Identity" -Number "28.21%" -Subtitle "Secure score updates can take up to 48 hours." -Icon "🏆" -IconColor "#ffc107" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px

            # Microsoft Entra Connect
            New-HTMLInfoCard -Title "Microsoft Entra Connect" -Number "✅ Enabled" -Subtitle "Last sync was less than 1 hour ago" -Icon "🔄" -IconColor "#198754" -Style "Standard" -ShadowIntensity 'Normal' -BorderRadius 2px
        }
    }

    # Enhanced styling showcase with different shadow intensities
    New-HTMLSection -HeaderText 'Enhanced Visual Showcase' {
        New-HTMLSection -Density Spacious {
            # ExtraNormal shadows for high-priority items
            New-HTMLInfoCard -Title "HIGH PRIORITY" -Number "Critical" -Subtitle "Maximum visibility shadow" -Icon "⚠️" -IconColor "#dc3545" -ShadowIntensity 'Normal' -ShadowColor 'rgba(220, 53, 69, 0.4)' -BorderRadius 2px

            # Normal colored shadows
            New-HTMLInfoCard -Title "Security Alert" -Number "Active" -Subtitle "Normal red shadow for attention" -Icon "🔴" -IconColor "#dc3545" -ShadowIntensity 'Normal' -ShadowColor 'rgba(220, 53, 69, 0.3)' -BorderRadius 2px

            # Normal with custom color
            New-HTMLInfoCard -Title "Performance" -Number "Good" -Subtitle "Green shadow indicates success" -Icon "✅" -IconColor "#198754" -ShadowIntensity 'Normal' -ShadowColor 'rgba(25, 135, 84, 0.3)' -BorderRadius 2px

            # Custom shadow settings
            New-HTMLInfoCard -Title "Custom Styling" -Number "Advanced" -Subtitle "Custom blur and spread values" -Icon "🎨" -IconColor "#6f42c1" -ShadowIntensity 'Custom' -ShadowBlur 15 -ShadowSpread 3 -ShadowColor 'rgba(111, 66, 193, 0.25)' -BorderRadius 2px
        }
    }

} -FilePath "$PSScriptRoot\Example-MicrosoftEntra.html" -TitleText "Microsoft Entra Interface Recreation" -Online -Show

r/usefulscripts • • Apr 17 '24

[PowerShell] Active Directory Replication Summary to Email or Microsoft Teams

16 Upvotes

I've not been very active in writing new blog posts in recent months, but I've been a bit preoccupied with coding different projects, and writing blog posts had to be put on hold. As I had some free time today, I wanted to share a quick script I wrote that is a wrapper around repadmin /replsummary

With this shortcode (after installing relevant modules), you can have a nicely formatted email to your mailbox.

$ReplicationSummary = Get-WinADForestReplicationSummary -IncludeStatisticsVariable Statistics

$Body = EmailBody {
    EmailImage -Source 'https://evotec.xyz/wp-content/uploads/2021/04/Logo-evotec-bb.png' -UrlLink '' -AlternativeText ' Logo' -Width 181 -Heigh 57 -Inline

    EmailText -Text "Dear ", "AD Team," -LineBreak
    EmailText -Text "Upon reviewing the resuls of replication I've found: "
    EmailList {
        EmailListItem -Text "Servers with good replication: ", $($Statistics.Good) -Color Black, SpringGreen -FontWeight normal, bold
        EmailListItem -Text "Servers with replication failures: ", $($Statistics.Failures) -Color Black, Red -FontWeight normal, bold
        EmailListItem -Text "Servers with replication delta over 24 hours: ", $($Statistics.DeltaOver24Hours) -Color Black, Red -FontWeight normal, bold
        EmailListItem -Text "Servers with replication delta over 12 hours: ", $($Statistics.DeltaOver12Hours) -Color Black, Red -FontWeight normal, bold
        EmailListItem -Text "Servers with replication delta over 6 hours: ", $($Statistics.DeltaOver6Hours) -Color Black, Red -FontWeight normal, bold
        EmailListItem -Text "Servers with replication delta over 3 hours: ", $($Statistics.DeltaOver3Hours) -Color Black, Red -FontWeight normal, bold
        EmailListItem -Text "Servers with replication delta over 1 hour: ", $($Statistics.DeltaOver1Hours) -Color Black, Red -FontWeight normal, bold
        EmailListItem -Text "Unique replication errors: ", $($Statistics.UniqueErrors.Count) -Color Black, Red -FontWeight normal, bold
    }

    if ($Statistics.UniqueErrors.Count -gt 0) {
        EmailText -Text "Unique replication errors:"
        EmailList {
            foreach ($ErrorText in $Statistics.UniqueErrors) {
                EmailListItem -Text $ErrorText
            }
        }
    } else {
        EmailText -Text "It seems you're doing a great job! Keep it up! 😊" -LineBreak
    }

    EmailText -Text "For more details please check the table below:"

    EmailTable -DataTable $ReplicationSummary {
        EmailTableCondition -Inline -Name "Fail" -HighlightHeaders 'Fails', 'Total', 'PercentageError' -ComparisonType number -Operator gt 0 -BackGroundColor Salmon -FailBackgroundColor SpringGreen
    } -HideFooter

    EmailText -LineBreak
    EmailText -Text "Kind regards,"
    EmailText -Text "Your automation friend"
}

I've also added a relevant Teams code.

For details (images and more know & how): https://evotec.xyz/active-directory-replication-summary-to-your-email/

Sources: https://github.com/EvotecIT/ADEssentials/blob/master/Public/Get-WinADForestReplicationSummary.ps1


r/usefulscripts • • Jul 17 '23

PowerShell HTML Server Racks Cabinet Live Diagram maker Demo

16 Upvotes

r/usefulscripts • • Apr 18 '23

[PYTHON] OpenAI-Code-Gen-and-Execution: A script that generates, executes, and checks Python code using the OpenAI API

Thumbnail
gist.github.com
16 Upvotes

r/usefulscripts • • Jan 20 '22

Why won't this bash script for Firefox consistently work?

16 Upvotes

Made this script to open Firefox in kiosk mode to several different websites and sometimes it works other times it will not open one or more of them and only see a blank tab when switching through. I have it setup with random sites for purposes of this post, but the results are always the same. Thought the wait command might help. It is always the second website/command that doesn't seem to work - not sure why that particular one.

Here's what happens...
https://imgur.com/a/SXDGhn3

And here's the code...

#!/bin/bash
# ------------------------------------------------------------------
# Title: HA-Kiosk.sh 
# Description: 
# A script that opens smart home resources in kiosk mode
#
# ------------------------------------------------------------------
firefox --kiosk --new-window http://www.google.com
# OK
wait
firefox --new-tab http://www.bing.com
wait
firefox --new-tab http://www.yahoo.com
# OK
wait
firefox --new-tab http://www.amazon.com
# OK
wait
firefox --new-tab http://www.walmart.com
# OK
wait
firefox --new-tab http://www.kohls.com
# OK

r/usefulscripts • • Feb 27 '20

[POWERSHELL] or [VBSCRIPT] script request. Take ownership of a folder/file structure. Add ntfs permission. Change owner back to original.

16 Upvotes

Hi guys. Hoping someone can help with this. As the title says I need a script that will:

-read the current owner of a folder structure

-Replace that owner with one of my choosing

-add a user/group to the ntfs security for the entire structure

-change owner back to original

I've seen a few 'solutions' for this but it required a lot of different modules to be loaded. Just looking for the cleanest way.

Thanks so much


r/usefulscripts • • Apr 24 '19

[REQUEST] Powershell script for monitoring Photoshop (or any process) usage

16 Upvotes

Hi! I'm looking for a script with what I could use to monitor 10-20 machines processes. I've managed to create a template which will output data as .csv table with computer name, username, the time elapsed but this only works with processes already running. What I'm looking for is a way to start measurement when a certain process (in this case photoshop pro) is launched and stop when the process is stopped. I most likely would then, when the sessions stops, send data to my InfluxDB and gather daily/weekly/monthly usage to view in Grafana.

all help is welcome!

I'd know how to do this in Linux with bash but Powershell isn't my best assets and client machines are Windows 10. :)


r/usefulscripts • • Sep 13 '18

[PowerShell] Module DictionaryFile

Thumbnail
sconstantinou.com
16 Upvotes

r/usefulscripts • • Jun 15 '18

[Request] Script to pull users and attributes from an AD Security group.

16 Upvotes

I was able to get a list for the whole domain:

Get-ADUser -Filter * -Properties * | select DisplayName,sAMAccountName,createtimestamp,LastlogonDate | Export-Csv T:\userReport.csv

but when I try to put in the AD group 'Finance Users'

Get-ADUser -Identity 'Finance Users' -Properties * | select DisplayName,sAMAccountName,createtimestamp,LastlogonDate | Export-Csv T:\userReport.csv

it fails consistently. What I'm doing wrong ?


r/usefulscripts • • Feb 14 '18

[Request] Powershell script to download and update DNS root hints.

16 Upvotes

I am looking for a script that can download the current list of DNS root hints from https://www.internic.net/zones/named.root then copy these values to all Windows 2016 DNS servers. We would like to run this on a scheduled basis to keep these updated as they seem to change.

Thanks!


r/usefulscripts • • Dec 05 '17

How do I use a batch file to create a folder in each subfolder with the name based on the level of the subfolder

16 Upvotes

My boss has decided to create a folder in each folder level on our server to designate what level it is from the base folder, so _A will be the first folder level, _B will be the second level, _C the third and so on as shown below

  • C:\Stuff

  • C:\Things

  • C:_Level A

  • C:\Stuff\Things

  • C:\Stuff_Level B

  • C:\Stuff\Things\More Things

  • C:\Stuff\Things_Level C

  • C:\Stuff\Things\More Things_Level D

  • C:\Things\Things

  • C:\Level B

  • C:\Things\Things\More Things

  • C:\Things\Things_Level C

  • C:\Things\Things\More Things_Level D

For what its worth I don't think its a great idea but it not my call. What annoyed me was watching one of our office staff doing this manually. I asked if it could wait a day or to while I figure out a more efficient way of doing it.

I'm sure there'll be a way to do it with a batch file but I can't figure it out.

Can anyone give me some direction.

Edit:- I've just been told we only need to go down 4 levels, so down to C:/Stuff/Things/More Stuff.


r/usefulscripts • • Dec 04 '17

Request: CMD, PowerShell, EXE with CMD script for backing up Chrome, Firefox profiles

16 Upvotes

As the title says.

We are working with SCCM task sequencing to create in-house tools for User State Migration. One of the current road blocks is figuring out command line scripts to automate backing up browser profiles.

Basically, would any of you happen to be able to provide some guidance for scripted commands that run in CMD, PowerShell, EXE with CMD to accomplish the above task?


r/usefulscripts • • Sep 26 '17

[Help] Powershell- Trying to create a variable that specifies arguments to tack on... Sort of?

16 Upvotes

Hey Scripters,

I'm working on some things in powershell and I came to a standstill.

I have a script that has pretty much ONLY GWMI commands to get system info(let's call it script2). I have another script that I would like to call that will specify specific options for the script: stuff like how to execute the commands in remote or local contexts.(script1)

Each command looks like this:

$var = gwmi Win32_Bios -Computer $name -Credential $cred -Impersonation 3

What I would like to do, if possible, is make a variable that houses the -computer,-credential,and -impersonation arguments so that they can be modified upon execution. That way the block could just be "$var = gwmi Win32_Bios", and IF the command SHOULD have additional args, they could be appended.

Essentially, i want to have a single block of code that I can add functions to, instead of having a switch or something that has redundantly written commands.

Script1 will pass options to script2, which will handle the options, and modify the commands accordingly. But alll the commands would still be gathered together in a single block, no matter what methods are used. If I could have a variable that would house these options for example, it would allow me to keep control and execution separate. Does that make sense?

I would also love to know if there is a way to do remote wmi queries(-computer arg) and save each output of them to a CSV(on the scriptrunner's host) , without passing in the remote machine's credentials every single time. I know you can do this with psRemoting but I don't know how I could work it with just direct remote queries.

Thanks for the help!


r/usefulscripts • • Aug 02 '17

Echoargs help, script request

16 Upvotes

I have the rest of my powershell working except when using this third party utility to stamp pdfs, it calls a cpdf from the same directory that powershell is ran and works if I manually type it, but when it gets to the $inputfile name and $outputfilename it acts as if nothings there, I echoed the contents of the inputfile name and output and it works, manually copied and pasted it from a log and it worked.

I'm thinking I have to do an invoke expression or & call program but I don't know how the argument list would work?

 .\cpdf.exe -add-text "%filename" -top 100pt -font "Times-Roman" -font-size 20 $inputfile -o $outputfile