Skip to content

Instantly share code, notes, and snippets.


Joe Cefoli jcefoli

View GitHub Profile
jcefoli / keepaliveScheduler.ps1
Last active Jan 5, 2021
Script that creates a scheduled task to keep your RDP session alive to work around nonsensical GPOs that inhibit productivity
View keepaliveScheduler.ps1
Keeps you productive by spoofing activity to prevent GPO idle timeouts, RDP disconnects, sleep, etc.
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 / 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 / isLocked.ps1
Created Aug 2, 2020
Check if domain user is locked out
View isLocked.ps1
[bool]$isLocked = (Get-ADUser 'username' -Properties LockedOut).LockedOut
if ($isLocked -eq $True) {
Write-Host "Account is locked"
} else {
Write-Host "Account is not locked"
jcefoli / github-auth.ps1
Created Aug 2, 2020
Authenticate with token to Download File from Raw Githubusercontent
View github-auth.ps1
$headers = @{'Accept' = 'application/json'}
$tokenString = "REPLACE-GITHUB-TOKEN-HERE" + ":x-oauth-basic"
$base64Auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(($tokenString)))
$headers.Add('Authorization',"Basic $base64Auth")
$content = Invoke-RestMethod -Uri "" -Headers $headers
jcefoli / pause-locally.ps1
Created Feb 4, 2020
Pause Script When Run Locally But not Remotely
View pause-locally.ps1
#Add to end of script
if ($PSSenderInfo) {
#Script was launched remotely. Do Not Pause
else {
#Script is running locally, pause
[void](Read-Host 'Press Enter to continue')
jcefoli / zoom_mute_global_hotkey.ahk
Last active Nov 4, 2019
[AutoHotKey] Set Ctrl-M Global Hotkey to Mute/Unmute Zoom Calls
View zoom_mute_global_hotkey.ahk
IfWinExist, ahk_class ZPContentViewWndClass
Send, !a
IfWinExist, ahk_class ZPFloatVideoWndClass
Send, !a
jcefoli / fizzbuzz.ps1
Created Oct 24, 2019
[Powershell Interview Question] The FizzBuzz Problem: Write a program that prints the numbers 1 to 100. For multiples of 3, print "Fizz". For multiples of 5, print "Buzz". FOr multiples of both 3 and 5, print "FizzBuzz".
View fizzbuzz.ps1
for ($x = 1; $x -le 100; $x++) {
$Output = ""
if ($x % 3 -eq 0) { $Output += "Fizz" }
if ($x % 5 -eq 0) { $Output += "Buzz" }
if ($Output -eq "") { $Output = $x }
Write-Output $Output
jcefoli / isLocked.ps1
Created Oct 15, 2019
Conditionally Check for AD Locked Out User Account
View isLocked.ps1
[bool]$isLocked = (Get-ADUser 'username' -Properties LockedOut).LockedOut
if ($isLocked -eq $True) {
Write-Host "Account is locked"
} else {
Write-Host "Account is not locked"
jcefoli / sendmail.ps1
Created Oct 14, 2019
Send Email in Powershell via .NET Net.Mail.SmtpClient & Net.Mail.MailMessage
View sendmail.ps1
$message = new-object Net.Mail.MailMessage;
$message.From = "";
$message.Subject = "Test by Joe";
$message.Body = "Message body here";
$smtp = new-object Net.Mail.SmtpClient("smtp.server.local", "25");
jcefoli / kickjenkins.ps1
Created Sep 24, 2019
Kick Jenkins Job With CSRF Protection Enabled [Powershell REST Request]
View kickjenkins.ps1
# Force TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Basic Auth Credentials
$user = 'changeme'
$pass = 'insecure-password'
# Handle Basic Auth (Hacky in Powershell)
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))