Tested scripts
PowerShell and Bash for real jobs. Each one says exactly what it was run on, and the ones nobody has run yet say so.
- Alert when a filesystem is nearly full (Bash)Checks every real filesystem and prints an alert for any at or above a usage threshold. It prints nothing when all is well, so it suits cron, which emails you only when there is output.
- Check TLS certificate expiry for a list of hosts (Bash)Connects to each host, reads its certificate and shows how many days are left. Run it weekly from cron so an expired certificate never surprises you.
- Clear a stuck print queue by resetting the spooler (PowerShell)Stops the Print Spooler, deletes the queued spool files and starts the service again. Use it when a job is stuck and cannot be cancelled from the printer queue window.
- Delete log files older than N days, dry run first (Bash)Finds log files older than a number of days in a directory and lists them. Only when you add –delete does it remove them. Use it to tidy an application log folder that has no rotation.
- Find stale Active Directory user accounts (PowerShell)Lists enabled AD user accounts that have not signed in for a set number of days, including ones that never signed in. Use it before an access review or a clean-up of leavers.
- Find the biggest directories under a path (Bash)Shows the largest directories directly under a path, biggest first, without crossing into other disks. Use it to drill down step by step when a filesystem fills up.
- Find the largest files under a folder (PowerShell)Lists the biggest files under a folder and all its subfolders, largest first. Reach for it when a drive is filling up and you need to know what is taking the space.
- Last boot time and uptime report (PowerShell)Shows when the computer last booted and how long it has been running, and warns if it has gone too long without a reboot. Handy after patching, when a machine claims it restarted but did not.
- Report free space on every drive (PowerShell)Shows size, free space and percent free for each fixed drive, and flags any below a threshold. Use it for a quick health check or as a scheduled task that exits with code 2 when space is low.
- Summarise failed SSH logins by IP and user (Bash)Counts failed SSH password attempts and shows the top source IPs and usernames tried. Use it to see whether a server is being brute-forced and who from.