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
{
"source": 2,
"revision": 4,
"description": null,
"createdBy": {
"displayName": "JohnLBevan",
"url": "https://app.vssps.visualstudio.com/A21454791-1e23-49e8-a35c-2389fa06a325/_apis/Identities/e2a7ca55-8633-4c52-9d34-8fb1a6f00aef",
"_links": {
"avatar": {
"href": "https://myCompany.visualstudio.com/_apis/GraphProfile/MemberAvatars/aad.MGQxMzkxMjItNjNjNy03MmViLWI3Y2QtM2EwMmRhZWEwYjc4"
@JohnLBevan
JohnLBevan / GeneratePassword.sql
Created November 1, 2018 18:05
A SQL Script for generating random passwords from a given set of characters
create table dbo.ValidPasswordChars
(
IdConsecutiveSeedZero int not null identity(0,1) primary key clustered --as the name suggests; don't leave gaps.
, aChar char(1) collate Latin1_General_CS_AS not null
)
go
--This creates the valid passwords as 0-9, a-z, A-Z. Other characters can easily be added as needed; the table approach has been used to avoid hardcoding valid chars / relying on ascii ranges where the related system may not allow specific values within those ranges
;with cte(asciiCode) as
@JohnLBevan
JohnLBevan / Search-Dfo365MissingLabels.ps1
Created September 28, 2018 06:38
This is a quick & dirty script for finding missing labels in DFO365 by comparing those in en-GB with those in es. A lot could be done to make this more re-usable (e.g. currently very focussed on the 2 stated languages / could easily be adapted to run for all languages / with optional filters to restrict the languages reported on); but for now it…
function Convert-XmlToHash {
[CmdletBinding(DefaultParameterSetName = 'XmlDocument')]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'XmlDocument')]
[System.Xml.XmlDocument]$XmlDocument
,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'XmlElement')]
[System.Xml.XmlElement]$InputObject
,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'XmlText')]
@JohnLBevan
JohnLBevan / Convert-XmlToHash.ps1
Created September 27, 2018 17:46
Convert XML to HashTable or JSON
function Convert-XmlToHash {
[CmdletBinding(DefaultParameterSetName = 'XmlDocument')]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'XmlDocument')]
[System.Xml.XmlDocument]$XmlDocument
,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'XmlElement')]
[System.Xml.XmlElement]$InputObject
,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'XmlText')]
@JohnLBevan
JohnLBevan / Get-Iso3166Csv.ps1
Last active April 16, 2021 14:38
ISO 3166 Country Codes. Data pulled from Wikipedia / hacky PowerShell script used to grab data included
clear-host
$data = Invoke-RestMethod -Method Get -Uri 'https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes'
$a = $data.SelectNodes('//*[local-name() = ''table''][./@class=''wikitable sortable'']//*[local-name() = ''tbody'']//*[local-name() = ''tr''][./*[local-name() = ''td'']]') | %{
[pscustomobject]@{
Name = $_.SelectSingleNode('(./*[local-name() = ''td''][1])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
FullName = $_.SelectSingleNode('(./*[local-name() = ''td''][2])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
Alpha2 = $_.SelectSingleNode('(./*[local-name() = ''td''][4])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
Alpha3 = $_.SelectSingleNode('(./*[local-name() = ''td''][5])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
Num = $_.SelectSingleNode('(./*[local-name() = ''td''][6])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
}
@JohnLBevan
JohnLBevan / Get-AdalAuthToken.ps1
Created September 20, 2018 17:13
OAuth2 for ADFS; without using the .Net ADAL library
<#
Since we have a few systems which can't ues .Net or Java libraries; but rather rely on raw
HTTP requests/response behaviour, I needed to find a way to demonstrate how to connect to
O365 services without making use of Microsoft.IdentityModel.Clients.ActiveDirectory.dll
An alternative approach is to use a client secret; however we didn't have access to this /
had to work out a quick solution to progress with PoC work using the information available to us
The below code effectively simulates this call:
@JohnLBevan
JohnLBevan / Get-AdalAuthToken.ps1
Created September 20, 2018 17:13
OAuth2 for ADFS; without using the .Net ADAL library
<#
Since we have a few systems which can't ues .Net or Java libraries; but rather rely on raw
HTTP requests/response behaviour, I needed to find a way to demonstrate how to connect to
O365 services without making use of Microsoft.IdentityModel.Clients.ActiveDirectory.dll
An alternative approach is to use a client secret; however we didn't have access to this /
had to work out a quick solution to progress with PoC work using the information available to us
The below code effectively simulates this call:
@JohnLBevan
JohnLBevan / Out-Application.ps1
Created September 20, 2018 10:33
Solution to stream output to a running instance of Notepad (or potentially other applications). https://stackoverflow.com/a/52422936/361842
#requires -Version 2
#based on Out-Notepad script from http://community.idera.com/powershell/powertips/b/tips/posts/send-text-to-notepad; only amended to allow appending.
function Out-Application {
[CmdletBinding(DefaultParameterSetName = 'ByString')]
Param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName = 'ByString')]
[AllowEmptyString()]
[String]$InputString
,
@JohnLBevan
JohnLBevan / ChromeV69.md
Last active September 14, 2018 16:09
Chrome v69 Fixes
  • Don’t hide URL content / display what’s used: chrome://flags/#omnibox-ui-hide-steady-state-url-scheme-and-subdomains
  • Don’t take up 2 rows for the title bar; go back to 1: chrome://flags/#top-chrome-md
@JohnLBevan
JohnLBevan / FileZillaLogParser.ps1
Created August 27, 2018 18:53
FileZilla Log Parser
[pscustomobject[]]$data = Get-Content 'C:\Program Files (x86)\FileZilla Server\Logs\fzs-2018-08-20.log' |
?{$_ -match '^\((?<session>\d+)\)\s(?<datetime>\d\d\/\d\d\/\d{4} \d\d:\d\d:\d\d) - (?<user>.+?) \((?<ip>\d+\.\d+\.\d+\.\d+)\)>\s(?<message>.*)$'} |
%{[pscustomobject]@{
Session = $matches.Session
Ip = $matches.Ip
Server = [System.Net.Dns]::Resolve($matches.Ip).HostName
User = $matches.User
DateTime = [DateTime]::ParseExact($matches.DateTime,'dd/MM/yyyy HH:mm:ss',$null)
Message = $matches.Message
}}