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 / ConvertTo-Icon.ps1
Created December 2, 2019 10:54
Create icon from an image file.
function ConvertTo-Icon {
[CmdletBinding(DefaultParameterSetName = 'BySuffix')]
Param (
# Specifies the source image filename
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Path
,
# the name of the .ico file
[Parameter(Mandatory = $true, ParameterSetName = 'ByLiteralName')]
@JohnLBevan
JohnLBevan / SP_Who2Wrapper.sql
Created November 11, 2019 12:19
SP_WHO2 Wrapper; to make filtering SP_WHO2's simple
declare @sp_who2 table (
Spid int
,[Status] varchar(255)
,[Login] varchar(255)
,HostName varchar(255)
,BlkBy varchar(255)
,DBName varchar(255)
,Command varchar(255)
,CpuTime int
,DiskIo int
@JohnLBevan
JohnLBevan / PSTelnetClient.ps1
Created October 16, 2019 12:44
PSv2 Compatible PowerShell Telnet (NVT) Client (https://tools.ietf.org/html/rfc854c)
Function New-TelnetClient {
[CmdletBinding()]
Param (
[Parameter()]
[string]$ComputerName = '127.0.0.1'
,
[Parameter()]
[int]$PortNo = 23
,
@JohnLBevan
JohnLBevan / BareFruitDnsHijackingFixNotes.md
Last active March 22, 2022 10:02
NXDomain DNS Hijacking BareFruit

ISP DNS Hijacking Notes

Symptoms

  • Web pages replaced with ISP's pages / adverts.
  • Failure to find/connect to expected resources.
  • Monitoring/tests of services that are down shows them as being up / responding to HTTP or ICMP pings.
  • Issues particularly common when using VPN.

Fixes per offender

@JohnLBevan
JohnLBevan / Get-SSMSNewConnectionServerList.ps1
Last active August 12, 2019 08:05
Get List of Servers from SSMS (i.e. historically used connections list from the New Connection dialogue)
Add-Type -Path (Get-Command 'Microsoft.SqlServer.Management.UserSettings.dll').Source
[bool]$loaded = $false
Get-Item -Path 'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ConnectionInfo\*\Microsoft.SqlServer.ConnectionInfo.dll' | Select-Object -ExpandProperty FullName | Sort-Object -Descending | ForEach-Object {if (!$loaded ){try {Add-Type -Path $_;Write-Verbose "Successfully loaded $_";$loaded=$true}catch{Write-Warning "Failed to load $_"}}}
[string]$settingsFilePath = (Resolve-Path (Join-Path -Path $env:APPDATA -ChildPath 'Microsoft/SQL Server Management Studio/*/SqlStudio.bin')).Path | Sort-Object -Descending | Select-Object -First 1
if ($settingsFilePath) {
try {
[System.IO.MemoryStream]$ms = [System.IO.File]::ReadAllBytes($settingsFilePath)
[System.Runtime.Serialization.Formatters.Binary.BinaryFormatter]$formatter = New-Object -TypeName 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter'
[Microsoft.SqlServer.Management.UserSettings.SqlStudio]$sqlStudio = $form
@JohnLBevan
JohnLBevan / Copy-DirectoriesOnly.ps1
Created May 23, 2019 11:28
Robocopy command to copy entire directory structure without files
$source = '\\path\to\source'
$destination = '\\path\to\dest'
robocopy "$source" "$destination" /zb /e /xf *
<#
See https://ss64.com/nt/robocopy.html for notes
/zb - If you get access denied on a folder, try using backup mode to access it (see http://www.rainingforks.com/blog/2015/suggested-robocopy-switches-explained.html for detail)
/e - Copy subfolders (/s), including empty ones.
/xf * - exclude files matching a filename pattern; in this case any filename, so only copy directories
Note: dest will contain the child folders of source; not source itself.
@JohnLBevan
JohnLBevan / Uninstall-Application.ps1
Created April 17, 2019 20:24
Helper for uninstalling apps / covers apps not listed in Win32_Process. Ironically created for WinRAR, but doesn't work with WinRAR, since that has its own uninstall.exe :/
#based on code from https://stackoverflow.com/questions/113542/how-can-i-uninstall-an-application-using-powershell
function Uninstall-Application {
[CmdletBinding(SupportsShouldProcess = $true)]
Param (
[Parameter(Mandatory = $true)]
@JohnLBevan
JohnLBevan / Copy-DiskCleanupFiles.ps1
Last active March 18, 2025 14:53
Clean Disk Space CBS Logs and CAB
copy-item 'C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe' 'c:\windows\system32\'
copy-item 'C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui' 'c:\windows\system32\en-US\'
@JohnLBevan
JohnLBevan / MattParkerCoinToss.ps1
Last active March 24, 2019 18:37
Simulation of the Coin Toss game, based on Matt Parker's Lecture https://youtu.be/6JwEYamjXpA?t=1870
#Simulation of https://youtu.be/6JwEYamjXpA?t=1870
function Get-CoinTossPossibleValues {@('H','T')}
function Get-CoinToss {
[CmdletBinding()]
Param (
[Parameter()]
[int]$NumberOfTosses = 1
,
[Parameter()]
[string[]]$PossibleValues = (Get-CoinTossPossibleValues)
@JohnLBevan
JohnLBevan / Get-Dfo365EncryptedSettings.ps1
Created March 7, 2019 15:20
Code to pull values from Dynamics 365 for Finance and Operations (aka DFO365 / unified operations) Web.Config file and decrypt values where required, to find relevant credential information used by the OneBox install.
[string[]]$Assemblies = @(
'C:\AOSService\webroot\bin\Microsoft.Dynamics.AX.Framework.EncryptionEngine.dll'
)
[string]$CSSource = @"
using System;
using Microsoft.Dynamics.Ax.Xpp.Security;
namespace n201903071243 //use an odd namespace so I don't have to reload powershell each time I want to tweak this code; just tweak the NS
{
public class Dfo365CertificateThumbprintProvider: Microsoft.Dynamics.Ax.Xpp.Security.ICertificateThumbprintProvider