Skip to content

Instantly share code, notes, and snippets.

Working from home

John Bevan JohnLBevan

Working from home
Block or report user

Report or block JohnLBevan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
JohnLBevan / PSPing.ps1
Created Jan 24, 2020
Powershell Ping - Gives a bit more detail than Test-Connection
View PSPing.ps1
[System.Collections.Generic.IDictionary[[uint32],[string]]]$statusCodes = New-Object -TypeName 'System.Collections.Generic.Dictionary[[uint32],[string]]'
# list from
Success (0)
Buffer Too Small (11001)
Destination Net Unreachable (11002)
Destination Host Unreachable (11003)
Destination Protocol Unreachable (11004)
Destination Port Unreachable (11005)
JohnLBevan / ConvertTo-Icon.ps1
Created Dec 2, 2019
Create icon from an image file.
View ConvertTo-Icon.ps1
function ConvertTo-Icon {
[CmdletBinding(DefaultParameterSetName = 'BySuffix')]
Param (
# Specifies the source image filename
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
# the name of the .ico file
[Parameter(Mandatory = $true, ParameterSetName = 'ByLiteralName')]
JohnLBevan / SP_Who2Wrapper.sql
Created Nov 11, 2019
SP_WHO2 Wrapper; to make filtering SP_WHO2's simple
View SP_Who2Wrapper.sql
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 / PSTelnetClient.ps1
Created Oct 16, 2019
PSv2 Compatible PowerShell Telnet (NVT) Client (
View PSTelnetClient.ps1
Function New-TelnetClient {
Param (
[string]$ComputerName = ''
[int]$PortNo = 23
JohnLBevan /
Last active Nov 19, 2019
NXDomain DNS Hijacking BareFruit

ISP DNS Hijacking Notes


  • 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 / Get-SSMSNewConnectionServerList.ps1
Last active Aug 12, 2019
Get List of Servers from SSMS (i.e. historically used connections list from the New Connection dialogue)
View Get-SSMSNewConnectionServerList.ps1
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 / Copy-DirectoriesOnly.ps1
Created May 23, 2019
Robocopy command to copy entire directory structure without files
View Copy-DirectoriesOnly.ps1
$source = '\\path\to\source'
$destination = '\\path\to\dest'
robocopy "$source" "$destination" /zb /e /xf *
See for notes
/zb - If you get access denied on a folder, try using backup mode to access it (see 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 / Uninstall-Application.ps1
Created Apr 17, 2019
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 :/
View Uninstall-Application.ps1
#based on code from
function Uninstall-Application {
[CmdletBinding(SupportsShouldProcess = $true)]
Param (
[Parameter(Mandatory = $true)]
JohnLBevan / Copy-DiskCleanupFiles.ps1
Last active Nov 25, 2019
Clean Disk Space CBS Logs and CAB
View Copy-DiskCleanupFiles.ps1
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 / MattParkerCoinToss.ps1
Last active Mar 24, 2019
Simulation of the Coin Toss game, based on Matt Parker's Lecture
View MattParkerCoinToss.ps1
#Simulation of
function Get-CoinTossPossibleValues {@('H','T')}
function Get-CoinToss {
Param (
[int]$NumberOfTosses = 1
[string[]]$PossibleValues = (Get-CoinTossPossibleValues)
You can’t perform that action at this time.