This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConvertFrom-WildcardPattern { | |
| param( | |
| [Parameter(Mandatory, ValueFromPipeline)] | |
| [WildcardPattern]$InputObject | |
| ) | |
| begin { | |
| $pctrProp = [WildcardPattern]. | |
| GetMember('PatternConvertedToRegex', [Reflection.BindingFlags]'NonPublic, Instance') | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Get-PSReadLineOption |Get-Content -LiteralPath { $_.HistorySavePath } |ForEach-Object { | |
| if($_.EndsWith('`')){ | |
| $last += "{0}`r`n" -f $_.Remove($_.Length - 1) | |
| }else{ | |
| "${last}${_}" | |
| $last = $null | |
| } | |
| } |Where-Object {$_ -like '*::*'} |ForEach-Object { | |
| # parse history entry as powershell script |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using namespace System.Reflection | |
| using namespace System.Reflection.Emit | |
| using namespace System.Runtime.CompilerServices | |
| # We'll attempt to construct a subset of the functionality of: | |
| # public record TestRecord(int M1, string M2); | |
| # | |
| # Namely, we'll generate: | |
| # - property getters (`get_M1()`, `get_M2()`), | |
| # - a public constructor (`TestRecord(int, int);`), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function target { | |
| param($Caller = $((Get-PSCallStack)[0].Command)) | |
| "'$Caller' called!" | |
| } | |
| function volunteerID { | |
| target -Caller $MyInvocation.MyCommand | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using namespace System.Collections | |
| function flatten | |
| { | |
| param( | |
| [IDictionary]$Dictionary, | |
| [string]$KeyDelimiter = ':' | |
| ) | |
| $newDict = @{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body *:not(code) { font-family: arial !important; } | |
| code {font-family: monospace !important;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 { |