Skip to content

Instantly share code, notes, and snippets.

View jcefoli's full-sized avatar

Joe Cefoli jcefoli

View GitHub Profile
@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
@jcefoli
jcefoli / pkmnGoldEncounterModifier.ps1
Last active March 20, 2024 22:36
Generates Gameshark codes for Pokemon Gold/Silver/Crystal to encounter a specific Pokemon at a specific level
<#
.DESCRIPTION
Generates Gameshark codes for Pokemon Gold/Silver/Crystal to encounter a specific Pokemon at a specific level
Takes user input for the Pokemon name and level and generates the codes
#>
function ConvertTo-Hex {
param (
[Parameter(Mandatory=$true)]
[int]$Number
@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 July 3, 2024 15:43
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