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 / 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 / build-mRemoteNG.ps1
Last active September 4, 2024 03:51
PowerShell Build Script for mRemoteNG latest dev branch
<#
.REQUIREMENTS
- Visual Studio 2022
- Wix Toolset 3.x
- .NET framework SDKs / core required by app
- Nuget
- git
#>
@jcefoli
jcefoli / imds-examples.ps1
Created September 3, 2024 15:53
AWS IMDSv2 Metadata Examples in Powershell
# Required for auth
$imdsv2Token = Invoke-RestMethod -Method PUT -Uri "http://169.254.169.254/latest/api/token" -Headers @{"X-aws-ec2-metadata-token-ttl-seconds" = "30"}
# Get Instance ID
$instanceId = Invoke-RestMethod -Uri "http://169.254.169.254/latest/meta-data/instance-id" -Headers @{"X-aws-ec2-metadata-token" = "$imdsv2Token"}
# Get Tag on Current Instance
$instanceId = Invoke-RestMethod -Uri "http://169.254.169.254/latest/meta-data/instance-id" -Headers @{"X-aws-ec2-metadata-token" = "$imdsv2Token"}
$ec2Tag = (Get-EC2Tag -Filter @{Name = "resource-type"; Values = "instance" }, @{Name = "resource-id"; Values = $instanceId }, @{Name = 'tag:t_something'; Values = "*" }).Value
@jcefoli
jcefoli / multidimensional-array-with-switches.ps1
Created July 23, 2024 17:52
Process a multidimensional array with switches based on environment flags and data within the array
param(
[switch]$dev,
[switch]$qa,
[switch]$prod
)
# Define the multidimensional array
$apps = @(
@{ stack = 'dev'; appName = "foo"; username = 'foo1'; password = "passy1" }
@{ stack = 'dev'; appName = "foo-dev1"; username = 'foo1'; password = "passy1" }
@jcefoli
jcefoli / imds-fix-routes.ps1
Created June 7, 2024 23:35
Fix AWS IMDS Routes When Moving Subnets
Import-Module c:\ProgramData\Amazon\EC2-Windows\Launch\Module\Ec2Launch.psm1; Add-Routes