Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathias R. Jessen IISResetMe

  • Booking.com
  • Netherlands
View GitHub Profile
@IISResetMe
IISResetMe / Find-VulnerableSchemas.ps1
Last active Aug 3, 2021
Find-VulnerableSchemas.ps1
View Find-VulnerableSchemas.ps1
# Dictionary to hold superclass names
$superClass = @{}
# List to hold class names that inherit from container and are allowed to live under computer object
$vulnerableSchemas = [System.Collections.Generic.List[string]]::new()
# Resolve schema naming context
$schemaNC = (Get-ADRootDSE).schemaNamingContext
# Enumerate all class schemas
View flatten.ps1
using namespace System.Collections
function flatten
{
param(
[IDictionary]$Dictionary,
[string]$KeyDelimiter = ':'
)
$newDict = @{}
View stackoverflow-font-hack.css
body *:not(code) { font-family: arial !important; }
code {font-family: monospace !important;}
@IISResetMe
IISResetMe / Get-InvocationQuote.ps1
Created Dec 31, 2020
Quote repeatable command invocation from [InvocationInfo] for simple parameter types
View Get-InvocationQuote.ps1
function Get-InvocationQuote
{
param([System.Management.Automation.InvocationInfo]$Invocation)
$cmdText = $Invocation.InvocationName
foreach($param in $Invocation.BoundParameters.GetEnumerator()){
$name = $param.Key
$value = switch($param.Value){
{$_ -is [string]} {
# Quote and escape all string values as sigle-quoted literals
@IISResetMe
IISResetMe / fib.ps1
Created Dec 31, 2020
Nega-fibonacci with (non-optimal) caching
View fib.ps1
# Z-fibonacci (or nega-fibonacci, see https://en.wikipedia.org/wiki/Fibonacci_number#Sequence_properties):
# F(n-2) = F(n) - F(n-1)
$function:fib = & {
$cache = [System.Collections.Generic.Dictionary[int,bigint]]::new()
-1..1 |Foreach-Object {
$cache.Add($_, $_)
}
return {
@IISResetMe
IISResetMe / MagicNumber.class.ps1
Created Dec 19, 2020
ECMA-335 SpecialName-based operator overloading in PowerShell classes
View MagicNumber.class.ps1
class MagicNumber
{
hidden [int] $_value
MagicNumber([int]$value)
{
$this._value = $value
}
# ECMA-335 I.10.3.2
View ConvertTo-List.ps1
function ConvertTo-List
{
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[object[]]$InputObject
)
begin {
$list = [System.Collections.Generic.List[object]]::new()
}
View DontTrustProgress.ps1
function Fake-Progress
{
$PSDefaultParameterValues['Write-Progress:Activity']='Making stuff up'
Write-Progress -Status 'Starting out' -PercentComplete 5
10..45|%{
Write-Progress -Status 'Doing stuff' -PercentComplete $_
Start-Sleep -Milliseconds 100
}
View XmlFileTreeGenerators.ps1
function Get-XmlFileTreeAppend
{
param(
[Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string[]]
${Path},
[Parameter(ParameterSetName='LiteralPath', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias('PSPath')]
[string[]]
View Invoke-RegexTerror.ps1
function Invoke-RegexTerror
{
[CmdletBinding(DefaultParameterSetName = 'ToBeOrNotToBe')]
param(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[int]$Count,
[Parameter(ParameterSetName = 'ToBeOrNotToBe')]
[switch]$Shakespeare,