Skip to content

Instantly share code, notes, and snippets.

View jimdiroffii's full-sized avatar
🏠
Working from home

Jim Diroff II jimdiroffii

🏠
Working from home
View GitHub Profile
@jimdiroffii
jimdiroffii / backupdir.sh
Created August 15, 2023 01:22
Backup Ubuntu Directory
backup_dir_function() {
# Log the start of the command
logger -p syslog.info "Starting backup process."
# must pass in a directory
directory="$1"
# Convert to absolute path if a relative path is given
if [[ ! "$directory" = /* ]]; then
directory="$(pwd)/$directory"
fi
@jimdiroffii
jimdiroffii / blockFiles.ps1
Last active August 26, 2023 16:40
Block all executables in a directory using firewall rules in Windows
# Check for administrator privileges
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
# Relaunch the script as an administrator
Start-Process powershell -Verb runAs -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`""
exit
}
# init directory existence check variable
$dirExists = $false
@jimdiroffii
jimdiroffii / copy.ps1
Created July 27, 2023 18:33
Local Network Backup with PowerShell
# Define the variables
# The server or root directory
$localserver = "\\<localserver>"
# Share
$share = "\share"
# Source data folders you wish to backup
$dataFolders = @("\backups", "\pics") # You can add more folders to this array if needed
@jimdiroffii
jimdiroffii / fourJobs.sh
Created July 26, 2023 16:55
Manages concurrent execution of nohup jobs with a maximum limit
#!/bin/bash
# Manages concurrent execution of nohup jobs with a maximum limit.
# Number of maximum concurrent jobs
MAX_JOBS=4
# List of commands you want to run with nohup
declare -a commands=(
"./sleepTest.sh"
@jimdiroffii
jimdiroffii / get-activeconnections.ps1
Created July 25, 2023 14:58
Display all active network connections using PowerShell
Function Get-ActiveConnections {
netstat -an | Where-Object { $_ -match 'ESTABLISHED|LISTENING' }
}
@jimdiroffii
jimdiroffii / md5hash.ps1
Created April 2, 2023 03:49
Powershell MD5 File Hashing with Table Resize
Get-FileHash .\FGT* -Algorithm MD5 | Format-Table -AutoSize
@jimdiroffii
jimdiroffii / removeDNSServer.ps1
Last active May 19, 2022 17:14
Remove all old DNS server entries from Forward and Reverse Zones in Active Directory DNS using Powershell
# Original idea: https://devblogs.microsoft.com/scripting/clean-up-domain-controller-dns-records-with-powershell/
# dnsSrv is only the only the hostname, no domain, of active DNS server, i.e. MYDNSSERVER
$dnsSrv = "<active-dns-server-hostname>"
# the server we are trying to remove, FQDN is Fully Qualified Domain Name, i.e. MYDNSSERVER.mydomain.local
$oldSrvFQDN = "<old-dns-FQDN>"
$oldSrvHost = "<old-dns-Hostname>"
$oldSrvIp = "<old-dns-ip-address>"
@jimdiroffii
jimdiroffii / testsmtp.py
Created March 22, 2022 16:30
SMTP Tester in Python
import smtplib
def prompt(prompt):
return input(prompt).strip()
fromaddr = prompt("From: ")
toaddrs = prompt("To: ").split()
print("Enter message, end with ^D (Unix) or ^Z (Windows):")
# Add the From: and To: headers at the start!
@jimdiroffii
jimdiroffii / tsprereq.ps1
Created February 24, 2021 23:03
Oracle Micros - Transaction Services Prerequisite Installer Script
<#
# Check DNS Configuration
#>
Write-Host "Checking DNS configuration..."
$error.clear()
try {Resolve-DnsName -Name microsoft.com -DnsOnly -QuickTimeout}
catch { "timeout period expired" }
if ($error) {
@jimdiroffii
jimdiroffii / removeapps.ps1
Created February 22, 2021 10:50
Remove Microsoft Store App Packages
# 3D Builder
Get-AppxPackage *3dbuilder* | Remove-AppxPackage
# Alarms & Clock
Get-AppxPackage *windowsalarms* | Remove-AppxPackage
# Calculator
Get-AppxPackage *windowscalculator* | Remove-AppxPackage
# Camera