Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / move-recursive.ps1
Last active Jun 19, 2021
Powershell: Move Files & Folders In Directory Recursively to Another Directory
View move-recursive.ps1
<#
The Windows move command is not recursive. Powershell's Move-Item moves the entire directory.
Robocopy /MOVE copies and deletes, which is slow.
This snippet takes files and folders in a directory (C:\SourceDir) and recursively moves them out of the dir and into another one C:\Destination.
#>
Get-ChildItem -Path "C:\SourceDir" -Recurse | Move-Item -Destination "C:\Destination"
@jcefoli
jcefoli / allkeys.php
Last active Jun 3, 2021
List All Key/Value Pairs in Redis using the Predis Library. Assumes that Redis is running locally on default port 6379 with no password auth
View allkeys.php
<?
//Include Predis library. See https://github.com/nrk/predis for more info
require "Predis/Autoloader.php";
//Connect to Redis
Predis\Autoloader::register();
try {
$redis = new Predis\Client();
$redis = new Predis\Client(array(
"scheme" => "tcp",
@jcefoli
jcefoli / keepaliveScheduler.ps1
Last active May 24, 2021
Script that creates a scheduled task to keep your RDP session alive to work around nonsensical GPOs that inhibit productivity
View keepaliveScheduler.ps1
<#
.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 / choice.bat
Created Aug 15, 2014
Template for Yes/No Choice input in batch files
View choice.bat
@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 / delete_pattern.lua
Created Oct 25, 2017
Redis: Delete Keys via Wildcard Pattern (Lua commandlet)
View delete_pattern.lua
EVAL "for i, name in ipairs(redis.call('KEYS', '*YOUR_PATTERN_HERE*')) do redis.call('DEL', name, 0); end" 0
@jcefoli
jcefoli / aws-ssm-param.ps1
Last active Mar 9, 2021
Powershell AWS CLI SSM Parameter Store Helper
View aws-ssm-param.ps1
<#
.SYNOPSIS
Helper script to manage SSM parameters
.PARAMETER name
SSM key name to set
.PARAMETER value
SSM key value to set
@jcefoli
jcefoli / msmq_message_copier.ps1
Last active Feb 22, 2021
Get MSMQ Queue Size and Copy All Messages to Another Queue
View msmq_message_copier.ps1
[Reflection.Assembly]::LoadWithPartialName("System.Messaging") | Out-Null
#Define Queue Connection Info Here (In this case, we're passing the IP to a clustered MSMQ instance)
$fromQueueConnString = "FormatName:Direct=TCP:172.1.1.1\private$\queue_to_copy_messages_from"
$toQueueConnString = "FormatName:Direct=TCP:172.1.1.1\private$\queue_to_copy_messages_to" # Make sure this queue exists - I don't create it and it might fail
# Get Queue Size - https://stackoverflow.com/a/2291087
$qsource = @"
public class QueueSizer
{
@jcefoli
jcefoli / rdp-keepalive.ps1
Last active Jan 5, 2021
RDP Keepalive using Kernel SetThreadExecutionState
View rdp-keepalive.ps1
$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 / SaveSpotlightImages.ps1
Last active Dec 2, 2020
Copies the Windows Spotlight lock screen images in Windows 10 to a "Windows Spotlight" folder in My Pictures.
View SaveSpotlightImages.ps1
<#
.DESCRIPTION
Copies the Windows Spotlight lock screen images in Windows 10 to a "Windows Spotlight" folder in My Pictures.
This script will intelligently sort through the temporary directory and will only copy images
that are 1920x1080. Since the filenames of the images can change, the script will also compare
SHA1 hashes of the existing so we don't copy duplicates.
.NOTES
Version: 1.0.2
@jcefoli
jcefoli / keepalive.ps1
Last active Nov 13, 2020
Powershell Computer Keepalive (Anti-Idle)
View keepalive.ps1
<#
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;