Skip to content

Instantly share code, notes, and snippets.

Working from home

John Bevan JohnLBevan

Working from home
View GitHub Profile
JohnLBevan /
Last active Jan 12, 2023
We have a java based system which uses the SqlServerXADataTable class from sqljdbc4.jar to connect to SQL Server. Whilst migrating this app to a new server I got the error `Connection test for 'MyDatabaseName' FAILED: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Serv…
import java.sql.*;
public class DBTest {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Please provide a connection string as an argument when calling this method; exactly 1 argument expected; received: " + args.length);
JohnLBevan / Get-MostRecentIISLogDate.ps1
Created Dec 8, 2022
Code for finding whether any file transfers have occured on any IIS FTP sites in the last year (has parameters to allow this to be tweaked more, though I've not passed those all the way down as they were beyond my requirement).
View Get-MostRecentIISLogDate.ps1
Function Import-IISLog {
Param (
[Parameter(Mandatory, ValueFromPipeline)]
[Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]$Encoding = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::Ascii
Begin {
JohnLBevan / Validate local user's credentials
Last active Nov 25, 2022
If you want to check the credentials you have for a local user account are correct, you can use this script (from: )
View Validate local user's credentials
$username = 'username'
$password = 'password'
$computer = $env:COMPUTERNAME
Add-Type -AssemblyName 'System.DirectoryServices.AccountManagement'
$obj = [System.DirectoryServices.AccountManagement.PrincipalContext]::new('machine',$computer)
$obj.ValidateCredentials("$computer\$username", $password)
JohnLBevan / WebDavClient.linq
Last active Nov 20, 2022
A basic c# client for testing webdav endpoints
View WebDavClient.linq
void Main()
var usr = @"myDomain\myUser";
var pwd = Util.GetPassword(usr); //linqpad util library
var uri = "";
var fn = @"c:\temp\filetouploadTestData.txt";
var rn = "remoteFilenameTestData.txt";
var wd = new BasicWebDavClient(usr, pwd, uri);
wd.Put(fn, rn);
JohnLBevan / PrtgSmtpsCertificateScan.ps1
Last active Nov 29, 2022
A first pass at a script for monitoriong SMTPS certificicate lifetimes in PRTG. Notes on usage here: Note; doesn't currently cover other TCP TLS certs (e.g. FTPS), but likely could with some additional tweaks...
View PrtgSmtpsCertificateScan.ps1
[Parameter(Mandatory = $true)]
[int]$Port = 25
[System.Security.Authentication.SslProtocols]$SslProtocols = [System.Security.Authentication.SslProtocols]::GetValues([System.Security.Authentication.SslProtocols])
JohnLBevan / GetOwernship.bat
Last active Oct 23, 2022
Get Ownership of / Access To Files
View GetOwernship.bat
:: Recursively take ownership of all files under a folder, and amend their access to grant full ownership to admins.
takeown /R /A /D Y /F c:\temp\path
:: /R = Recursive
:: /A = Ownership to Admins
:: /D Y = answer Yes to any questions (/D N would answer No)
:: /F c:\temp\path = which path to run the command against
icacls c:\temp\path /grant Administrators:F /T /C
:: c:\temp\path The path to run the command against
JohnLBevan / Export-X509CertToPemFiles.ps1
Created Jul 18, 2022
The start of a function for working with PEM certs in PS. Note: functionality for handling encrypted private keys was too complex wtihout third party libraries (e.g. BouncyCastle), so this doesn't full work yet / is a work in progress. There are some potential solutions for .net 6 out there (PemEncoding.Write), but that wasn't an option for the …
View Export-X509CertToPemFiles.ps1
Function Export-X509CertToPemFiles {
Param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
JohnLBevan / Kusto: Find all Azure App Gateway Listeners & HostNames
Created Jun 16, 2022
A kusto query which can be run under the Azure Resource Graph Explorer ( to get a list of hostnames/listeners configured on all app gateways under your subscriptions.
View Kusto: Find all Azure App Gateway Listeners & HostNames
| where type =~ 'microsoft.resources/subscriptions'
| project SubscriptionName=name, subscriptionId
) | join kind = inner
| where type =~ ''
| project subscriptionId, AppGateway=name, httpListeners = properties['httpListeners']
) on subscriptionId
View rainbow.html
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Google Demo</title>
<style type="text/css" media="screen">
.rainbow-text {
background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
JohnLBevan / Get-HttpUrlRedirects.ps1
Last active Nov 28, 2022
Shows all the redirects which occur when hitting a given URI. Useful for checking how HTTP301 / HTTP302 / HTTP307 rules are configured. `Hostname` parameter allows us to handle cases where DNS doesn't match the hostname on our listener; useful for testing pre-go-live without updating your hosts file.
View Get-HttpUrlRedirects.ps1
function Get-HttpUrlRedirects {
Param (