Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / valkey-data-tool.py
Last active March 19, 2025 22:42
Script to Import/Export data from Valkey/Redis DBs. Very useful to migrate from Redis 7.4 to Valkey (development diverged; Valkey is based off of Redis 7.2.x and the RDB formats are no longer compatible). Assumes Valkey/Redis server is running locally on the default port without any passwords but you can change all of that
import redis
import json
# Connect to Valkey/Redis
client = redis.Redis(host='127.0.0.1', decode_responses=True)
def dump_to_json(output_file="redis_dump.json"):
all_data = {}
cursor = 0
@jcefoli
jcefoli / keepaliveScheduler.ps1
Last active March 14, 2025 15:52
Script that creates a scheduled task to keep your RDP session alive to work around nonsensical GPOs that inhibit productivity
<#
.SYNOPSIS
Keeps you productive by spoofing activity to prevent GPO idle timeouts, RDP disconnects, sleep, etc.
.Description
This script creates a Scheduled Task that runs at login which uses Kernel SetThreadExecutionState to prevent GPOs
from disconnecting your RDP session. Will also prevent sleeping/screensavers/display timeouts
See the example below for a one liner that will download and execute this script directly from GitHub!
@jcefoli
jcefoli / start-ec2-instance.sh
Created February 25, 2025 16:45
Bash/AWSCLI/JQ method to start an EC2 Instance and Wait for Ping Status Online (Instance ID can be an ADO variable or modified)
#!/bin/bash
INSTANCE_ID="$(InstanceID)"
REGION="us-east-2"
PING_STATUS=""
aws ec2 start-instances --instance-ids $INSTANCE_ID --region $REGION
while :; do
# Run the AWS CLI command and capture the response
@jcefoli
jcefoli / RenameWindowsUserDir.md
Created February 15, 2025 22:01
Rename Windows User Profile Directory

Instructions to Rename User Profile Directory

In Windows 11, when setting up your MSFT Account, the OS defaults to the first 5 characters of your MSFT account for your user profile directory (ie- C:\Users\12345). These instructions are how to rename the directory safely.

Steps

  1. Enable local administrator account and log in as it

  2. Make replacements in Windows Registry. Find the acct sid and change the username there (Update this with the exact path)

@jcefoli
jcefoli / Move-For-Deletion.ps1
Created February 15, 2025 08:12
Move all contents of a directory for future disposal
<#
.SYNOPSIS
Moves contents from one directory to a temporary deletion folder.
.DESCRIPTION
This script safely moves files and folders from a specified directory to a randomly named
temporary folder. It preserves the original directory structure and handles the move operation
with error suppression.
Why? When you need to delete a directory such as a large .NET app webroot, there can be hundreds of
@jcefoli
jcefoli / uninstall-splunk.ps1
Created February 6, 2025 21:19
Uninstall Splunk Universal Forwarder (Windows)
# Get the list of installed programs
$installedPrograms = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName
$containsSplunk = $installedPrograms.DisplayName -like "*UniversalForwarder*"
if ($containsSplunk) {
Write-Output "[INFO] Splunk found. Removing"
if (Get-Service -Name SplunkForwarder -ErrorAction SilentlyContinue) {
Start-Process -FilePath "C:\Program Files\SplunkUniversalForwarder\bin\splunk.exe" -ArgumentList "stop" -Wait -NoNewWindow
}
$productCode = Get-WmiObject Win32_Product -Filter "name='UniversalForwarder'" | ForEach-Object { $_.IdentifyingNumber }
@jcefoli
jcefoli / ps2exe.ps1
Created February 4, 2025 17:01
PS2Exe - Create exe from powershell script (hide console)
#Requires -RunAsAdministrator
#Requires -PSEdition Desktop
Import-Module ps2exe
ps2exe .\your-powershell.ps1 your-exe.exe -noconsole -company 'JoeCorp' -product 'AppProductName' -description 'App Description'
@jcefoli
jcefoli / rdp-keepalive.ps1
Last active January 9, 2025 22:36
RDP Keepalive using Kernel SetThreadExecutionState
$host.ui.RawUI.WindowTitle = "Idle Keepalive"
$dotNetCode = @'
[DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);
'@
$ste = Add-Type -memberDefinition $dotNetCode -name System -namespace Win32 -passThru
$ES_CONTINUOUS = [uint32]"0x80000000" #Requests that the other EXECUTION_STATE flags set remain in effect until SetThreadExecutionState is called again with the ES_CONTINUOUS flag set and one of the other EXECUTION_STATE flags cleared.
$ES_AWAYMODE_REQUIRED = [uint32]"0x00000040" #Requests Away Mode to be enabled.
@jcefoli
jcefoli / choice.bat
Created August 15, 2014 22:33
Template for Yes/No Choice input in batch files
@ECHO OFF
:start
SET choice=
SET /p choice=Do something? [N]:
IF NOT '%choice%'=='' SET choice=%choice:~0,1%
IF '%choice%'=='Y' GOTO yes
IF '%choice%'=='y' GOTO yes
IF '%choice%'=='N' GOTO no
IF '%choice%'=='n' GOTO no
IF '%choice%'=='' GOTO no
@jcefoli
jcefoli / keepalive.ps1
Last active October 28, 2024 18:19
Powershell Computer Keepalive (Anti-Idle)
<#
This script will prevent GPOs from enabling the screensaver, shutting off your screen, or force-locking your workstation
It works by sending an F15 keystroke every minute (only if there have been no keystrokes or mouse movement for 30 seconds)
Be green - if you want to use this, power off your monitor(s)!
#>
Add-Type @'
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;