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
JohnLBevan / PSPing.ps1
Created Jan 24, 2020
Powershell Ping - Gives a bit more detail than Test-Connection
View PSPing.ps1
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)
@JohnLBevan
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)]
[string]$Path
,
# the name of the .ico file
[Parameter(Mandatory = $true, ParameterSetName = 'ByLiteralName')]
@JohnLBevan
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
JohnLBevan / PSTelnetClient.ps1
Created Oct 16, 2019
PSv2 Compatible PowerShell Telnet (NVT) Client (https://tools.ietf.org/html/rfc854c)
View PSTelnetClient.ps1
Function New-TelnetClient {
[CmdletBinding()]
Param (
[Parameter()]
[string]$ComputerName = '127.0.0.1'
,
[Parameter()]
[int]$PortNo = 23
,
@JohnLBevan
JohnLBevan / BareFruitDnsHijackingFixNotes.md
Last active Nov 19, 2019
NXDomain DNS Hijacking BareFruit
View BareFruitDnsHijackingFixNotes.md

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 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
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 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 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 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 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
JohnLBevan / MattParkerCoinToss.ps1
Last active Mar 24, 2019
Simulation of the Coin Toss game, based on Matt Parker's Lecture https://youtu.be/6JwEYamjXpA?t=1870
View MattParkerCoinToss.ps1
#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)
You can’t perform that action at this time.