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 / 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 29, 2022 14:31
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()]
@JohnLBevan
JohnLBevan / Fix-ExcelWorkbookXml.ps1
Created April 13, 2022 11:15
Fix Excel's Name Manager (workbook contains too many bad references in named ranges) issue
# Thanks to [Reddit](https://www.reddit.com/r/excel/comments/70r89w/need_to_delete_thousands_of_errored_named_ranges/i4huccg)
# for the tip on resolving the name manager issue
# once you've extracted your XLSX file as a zip, find the `workbook.xml` file (should be under the `xl` subfolder)
$wbPath = 'C:\Temp\MyExtractedXlsx\xl\workbook.xml'
# open this XML file / parse it as XML
$wb = [xml](Get-Content -Path $wbPath -encoding UTF8 -Raw)
# find all `definedName` elements which contain the string `#REF!`.
@JohnLBevan
JohnLBevan / Convert-PemToX509Cert.ps1
Last active April 7, 2022 10:12
Simple script to convert PEM to X509 Certs; useful if you want to check which certs a PEM relates to, or check the order of the certs in the chain.
function Convert-PemToX509Cert {
Param (
[Parameter(Mandatory)]
[string]$Path
,
[Parameter()]
[System.Text.Encoding]$Encoding = [System.Text.Encoding]::UTF8
)
$options = [System.Text.RegularExpressions.RegexOptions]::CultureInvariant -bor [System.Text.RegularExpressions.RegexOptions]::Singleline
$regex = [System.Text.RegularExpressions.RegEx]::new('\-{5}BEGIN CERTIFICATE\-{5}(?<CERT>.*?)\-{5}END CERTIFICATE\-{5}', $options)