Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@jcefoli
jcefoli / tstWan.ps1
Last active January 27, 2024 09:49
Windows Sandbox Connection Tester & Reboot
# This will ping google to test for a WAN connection and reboot if it fails
# Workaround to my Windows Sandbox always losing network
# The weird logging to write-host/write-output is designed to be used with Windows task scheduler (interactive logon) or via console directly
$host.ui.RawUI.WindowTitle = "Network Checker"
Clear-Host
$dt = (get-date).toString()
Write-Host "Network Check Running. Logfile: C:\Users\$($env:username)\networkCheck.log"
Write-Output "[$dt] Network Check Running. Logfile: C:\Users\$($env:username)\networkCheck.log" | Out-File -FilePath "C:\Users\$($env:username)\networkCheck.log" -Encoding utf8 -Append
@jcefoli
jcefoli / fix_windows_ssh_privkey_permission.ps1
Last active December 1, 2023 05:58
Fix OpenSSH private key permissions on Windows (Solves Windows SSH: Permissions for 'private-key' are too open)
param (
[Parameter(Mandatory=$true)]
[string]$privateKeyFilePath
)
# Remove inheritance from the private key file to prevent inheriting permissions from parent directories
. icacls $privateKeyFilePath /c /t /Inheritance:d
# Grant full control to the current user for keys within the user profile directory
. icacls $privateKeyFilePath /c /t /Grant ${env:UserName}:F
@jcefoli
jcefoli / asus-cheatsheet.txt
Last active August 31, 2023 17:15
[Asus Router] Useful SSH Commands
# Modify Hosts file (/jffs/configs/hosts.add)
service restart_dnsmasq
# Parse Custom Client List
nvram get custom_clientlist | sed 's/</\n/g; s/>/\t/g' | sed 's/^/custom\t/' | tail '+2' | sed 's/\(^.*\)\(\t.*\)\(\t[0-9A-F][0-9A-F]:.*$\)/\1\3\2/'
# Remove Logged in User restriction
nvram unset login_ip
nvram commit
@jcefoli
jcefoli / random-ip-in-cidr.ps1
Last active July 25, 2023 21:33
[pwsh] Generate a random IP address in a given CIDR range
function Get-RandomIPAddressInCIDR {
param (
[string]$CIDR
)
# Split the CIDR into network address and subnet mask
$networkAddress, $subnetMaskBits = $CIDR -split '/'
$subnetMaskBits = [int]$subnetMaskBits
if ($subnetMaskBits -eq 32) {
@jcefoli
jcefoli / file_datetime.ps1
Created May 10, 2023 15:58
File DateTimeStamp Output
$outputFileName = "C:\Temp\File_{0:yyyyMMdd}_{0:HHmmss}.csv" -f (Get-Date)
#C:/Temp/File_20230510_115723.csv
@jcefoli
jcefoli / lolbanner.sh
Created April 24, 2023 14:06
LolBanner Setup Script (Debian) - Create colorful text banners using the 3d.flf font, figlet and lolcat (wrapped by a bash function called lolcat)
#!/usr/bin/env bash
sudo apt install figlet lolcat --no-install-recommends -y
wget https://raw.githubusercontent.com/xero/figlet-fonts/master/3d.flf -P ~/.local/share/fonts/
sudo tee ~/.bashrc << 'EOF'
lolbanner ()
{
echo
figlet -f ~/.local/share/fonts/3d.flf $@ | lolcat
@jcefoli
jcefoli / Update-SessionEnvironment.ps1
Created January 27, 2023 19:53
Refresh Path In Powershell Session Using Chocolatey
# Use chocolatey to refresh the path
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1"
Update-SessionEnvironment -Full
@jcefoli
jcefoli / pwshIntellisense.ps1
Created December 19, 2022 17:05
Powershell Intellisense
## https://devblogs.microsoft.com/powershell/psreadline-2-2-6-enables-predictive-intellisense-by-default ##
# Get Configuration
Get-PSReadLineOption
## Get Intellisense Option
(Get-PSReadLineOption).PredictionSource
# Command History Path
(Get-PSReadLineOption).HistorySavePath
@jcefoli
jcefoli / dns-cluster-permissions.ps1
Last active November 26, 2022 04:59
Windows Cluster / DNS: Assign Full Rights to Cluster, Listener and Computer Objects (Bug workaround)
# Get a listing of all clusters (CLUS)
$clusters = Get-ADComputer -Filter "Name -like 'CLUS'"
#Set Domain
$DNSServer = (Get-ADDomain).PDCEMulator
#Set DNS Zone
$DNSZone = "dev.contoso.com"
#Iterate through the list of clusters get dns and add the appropriate full control objects (listener, cluster)
@jcefoli
jcefoli / iisHeaders.ps1
Created September 16, 2022 21:40
IIS Header Examples
Import-Module WebAdministration
# Add Custom Header - Server Level
Add-WebConfigurationProperty -PSPath MACHINE/WEBROOT/APPHOST `
-Name . -Filter system.webServer/httpProtocol/customHeaders `
-AtElement @{name = "X-Custom" ; value = 'value' }
#Remove Server: Microsoft-IIS/10.0 Header
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/security/requestFiltering" -name "removeServerHeader" -value "True"