Skip to content

Instantly share code, notes, and snippets.

View JohnLBevan's full-sized avatar
🏠
Working from home

John Bevan JohnLBevan

🏠
Working from home
View GitHub Profile
@JohnLBevan
JohnLBevan / TerraformNotes.md
Last active July 23, 2020 10:19
Useful articles and hints around Terraform / Terragrunt
@JohnLBevan
JohnLBevan / RateLimitExcel.ps1
Created July 10, 2020 06:26
Dirty hack to prevent 1 user's Excel from hogging CPU and impacting all other users on the same RDP session. Proper solution would be to implement auto-scaling (that's in the pipeline, but this gets us around the immediate issue)
[CmdletBinding()]
Param()
$noProcessors = (Get-WmiObject -class 'Win32_Processor' -Namespace 'root\cimv2').NumberOfLogicalProcessors
if ($noProcessors -gt 1) {
$maxAffinity = [Math]::Pow(2, $noProcessors) - 1 # i.e. this signfies that all processors are assigned to a process
$procsPerUser = [Math]::Ceiling($noProcessors / 3) # i.e. allow users to use 1/3rd the available processors (rounded up)
while ($true) {
@JohnLBevan
JohnLBevan / fixgit.sh
Last active June 16, 2020 17:20
Fix issues caused by ssh agent not running
# git@github.com: Permission denied (publickey).
# fatal: Could not read from remote repository
# Please make sure you have the correct access rights and the repository exists
# run git bash
#ssh-agent
eval `ssh-agent`
# should output: Agent pid ####
# change the filename in the below to match your key file (found under `%userprofile%/.ssh`)
@JohnLBevan
JohnLBevan / FilezillaLogParser.ps1
Last active December 27, 2022 13:38
Turn filezilla logs into something you can work with
class FzLogEntry {
[long]$SessionId
[DateTime]$DateTime
[string]$User
[version]$ClientIp # I've used version assuming it's always IPv4... if that assumption's wrong we may have to amend to string
[string]$Msg
FzLogEntry(){}
}
Function Get-FzLogData {
@JohnLBevan
JohnLBevan / StayFocusd.json
Created April 23, 2020 08:11
Stay Focusd block rules. Extension: https://chrome.google.com/webstore/detail/stayfocusd/laankejkbhbdhmipfmgcngdelahlfoji?hl=en Settings: chrome-extension://laankejkbhbdhmipfmgcngdelahlfoji/options.html#importExportTab
{
"SYNC": {
"blacklist": {
"facebook.com": {},
"twitter.com": {},
"ycombinator.com": {}
},
"storageMap": {
"backup-1587628948311": 3,
"backup-1587628948312": 3,
@JohnLBevan
JohnLBevan / Repair-RemoteSafeModeBoot.ps1
Created April 2, 2020 13:29
Take a remote computer out of safe mode (with networking) / put it back into normal mode.
Function Repair-RemoteSafeModeBoot {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]$ComputerName
)
if (-not (Test-Connection -ComputerName $ComputerName -Quiet -Count 1 -ErrorAction 'Stop')) {
throw "Could not ping $ComputerName; no attempt made to fix it"
}
$os = Get-WmiObject -ComputerName $ComputerName -Class 'Win32_OperatingSystem' -ErrorAction 'Stop'
@JohnLBevan
JohnLBevan / UsefulRegistryKeys.ps1
Created March 5, 2020 09:33
Useful Windows Registry Keys
#
# A collection of registry keys wrapped in scripts to help use them and with comments on what they're for
#
<#
SYMPTOM
User gets a temporary profile every time they log on
CAUSE
.bak entry for the user in the profile list
FIX
@JohnLBevan
JohnLBevan / New-DummyFile.ps1
Last active March 4, 2020 10:36
Create a binary file of a given size full of random data - useful when we want to test things like disk io / network performance of copying files, ensuring there are no patterns allowing for unwanted optimizations to kick in
function New-DummyFile {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
Param (
# full path to file to be created
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Path
,
# the size of the file to be created (you can use shorthand terms like 1GB to populate this)
[Parameter(Mandatory = $true)]
[UInt64]$FileSizeBytes # use uint to avoid negatives; use int64 to ensure we can hold values in terrabytes
@JohnLBevan
JohnLBevan / GetADUserLastLogonDate.linq
Created March 3, 2020 09:18
A C# implementation of Get-ADUserLastLogon that works for a single server, running for all DCs in a given domain's forest / doesn't rely on the DC having web services installed. For a similar PowerShell script (which does rely on web services) see: https://sid-500.com/2019/08/12/powershell-get-last-domain-logon-with-get-aduserlastlogon/
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.DirectoryServices.AccountManagement.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.DirectoryServices.dll</Reference>
<Namespace>System.DirectoryServices</Namespace>
<Namespace>System.DirectoryServices.AccountManagement</Namespace>
<Namespace>System.DirectoryServices.ActiveDirectory</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
void Main()
@JohnLBevan
JohnLBevan / PSPing.ps1
Created January 24, 2020 16:44
Powershell Ping - Gives a bit more detail than Test-Connection
Param([string]$ComputerName)
[System.Collections.Generic.IDictionary[[uint32],[string]]]$statusCodes = New-Object -TypeName 'System.Collections.Generic.Dictionary[[uint32],[string]]'
# list from https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wmipicmp/win32-pingstatus
@'
Success (0)
Buffer Too Small (11001)
Destination Net Unreachable (11002)
Destination Host Unreachable (11003)
Destination Protocol Unreachable (11004)
Destination Port Unreachable (11005)