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 / DBTest.java
Last active January 12, 2023 17:41
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 com.microsoft.sqlserver.jdbc.*;
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);
return;
@JohnLBevan
JohnLBevan / Get-MostRecentIISLogDate.ps1
Created December 8, 2022 07:34
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).
Function Import-IISLog {
[CmdletBinding()]
Param (
[Parameter(Mandatory, ValueFromPipeline)]
[System.IO.FileInfo]$Path
,
[Parameter()]
[Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]$Encoding = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::Ascii
)
Begin {
@JohnLBevan
JohnLBevan / Validate local user's credentials
Last active February 8, 2024 18:16
If you want to check the credentials you have for a local user account are correct, you can use this script (from: https://blog.idera.com/database-tools/test-local-user-account-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
JohnLBevan / WebDavClient.linq
Last active March 9, 2023 14:28
A basic c# client for testing webdav endpoints
void Main()
{
var usr = @"myDomain\myUser";
var pwd = Util.GetPassword(usr); //linqpad util library
var uri = "https://webdavendpoint.example.com/somefolder/";
var fn = @"c:\temp\filetouploadTestData.txt";
var rn = "remoteFilenameTestData.txt";
var wd = new BasicWebDavClient(usr, pwd, uri);
wd.Put(fn, rn);
@JohnLBevan
JohnLBevan / PrtgSmtpsCertificateScan.ps1
Last active November 17, 2025 11:59
A first pass at a script for monitoriong SMTPS certificicate lifetimes in PRTG. Notes on usage here: https://www.paessler.com/manuals/prtg/exe_script_advanced_sensor. Note; doesn't currently cover other TCP TLS certs (e.g. FTPS), but likely could with some additional tweaks...
Param(
[Parameter(Mandatory = $true)]
[string]$ComputerName
,
[Parameter()]
[int]$Port = 25
,
[Parameter()]
[System.Security.Authentication.SslProtocols]$SslProtocols = [System.Security.Authentication.SslProtocols]::GetValues([System.Security.Authentication.SslProtocols])
,
@JohnLBevan
JohnLBevan / GetOwernship.bat
Last active October 23, 2022 17:39
Get Ownership of / Access To Files
:: 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
JohnLBevan / Export-X509CertToPemFiles.ps1
Created July 18, 2022 13:14
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 …
Function Export-X509CertToPemFiles {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate
,
[Parameter(Mandatory = $true)]
[System.IO.FileInfo]$FullChainPath
,
[Parameter(Mandatory = $true)]
@JohnLBevan
JohnLBevan / Kusto: Find all Azure App Gateway Listeners & HostNames
Created June 16, 2022 11:51
A kusto query which can be run under the Azure Resource Graph Explorer (https://portal.azure.com/#view/HubsExtension/ArgQueryBlade) to get a list of hostnames/listeners configured on all app gateways under your subscriptions.
(
resourcecontainers
| where type =~ 'microsoft.resources/subscriptions'
| project SubscriptionName=name, subscriptionId
) | join kind = inner
(
resources
| where type =~ 'microsoft.network/applicationgateways'
| project subscriptionId, AppGateway=name, httpListeners = properties['httpListeners']
) on subscriptionId
<!DOCTYPE html>
<html>
<head>
<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
JohnLBevan / Get-HttpUrlRedirects.ps1
Last active November 28, 2022 16:09
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.
function Get-HttpUrlRedirects {
[CmdletBinding()]
Param (
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Url
,
[Parameter()]
[AllowNull()]
[AllowEmptyString()]