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
| ## | |
| ## regex-based String.Format emulator | |
| ## | |
| ## In order to better understand how String.Format (or it's corresponding PowerShell operator `-f`), it might be useful to | |
| ## attempt to implement it from (relative) scratch. | |
| ## | |
| ## String.Format composite templates consist of verbatim string contents interspersed with the following macro syntax: | |
| ## | |
| ## "{" <index>["," <width>][":" <formatString>] "}" | |
| ## |
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.Generic | |
| using namespace System.Management.Automation.Language | |
| <# | |
| PSGraft is a generalization of the mutating visitor pattern used in PSProfiler | |
| See `Get-Help Graft-Code -Examples` after dot-sourcing this file. | |
| #> | |
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
| class IndisposableStream : IO.Stream { | |
| hidden [IO.Stream] $_inner | |
| IndisposableStream([IO.Stream]$inner) { | |
| $this._inner = $inner | |
| } | |
| # proxy (almost) everything back to the inner stream object | |
| hidden [bool] get_CanRead() { return $this._inner.CanRead } | |
| hidden [bool] get_CanWrite() { return $this._inner.CanWrite } |
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
| $array = 1..10 | |
| for ($i = 0; $i -lt $array.Length; $i++) { | |
| Write-Host "Loop iteration $($i + 1): #$($array[$i])" | |
| if ($i -eq $array.Length - 1) { Write-Host "Last loop!" } | |
| } |
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
| $array = 1..10 | |
| for ($i = 0; $i -lt $array.length; $i++) { | |
| Write-Host "Loop #$($array[$i])" | |
| if ($i = $array.length) { Write-Host "Last loop!" } | |
| } |
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
| # Define the list of objects | |
| $objects = @( | |
| # Level 1 | |
| [PSCustomObject]@{ DisplayName = "Root1"; ID = 1; ParentID = $null } | |
| [PSCustomObject]@{ DisplayName = "Root2"; ID = 2; ParentID = $null } | |
| # Level 2 | |
| [PSCustomObject]@{ DisplayName = "Child1.1"; ID = 3; ParentID = 1 } | |
| [PSCustomObject]@{ DisplayName = "Child1.2"; ID = 4; ParentID = 1 } |
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
| class StringBase { | |
| hidden static [string] $_pattern = '(?!)' | |
| hidden [string] $_value | |
| # define single ctor with input string as its only parameter | |
| StringBase([string]$value) { | |
| $this._value = $value | |
| if (-not $this.TryParse()) { | |
| throw [ArgumentException]::new("Failed to parse input string '$value'", 'value') | |
| } |
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-AvailableLicenseTemplates { | |
| [CmdletBinding()] | |
| param () | |
| process { | |
| Write-Host "`$PSScriptRoot:" $PSScriptRoot -ForegroundColor Green | |
| # Define the parent directory containing the folders | |
| $ParentDirectory = "$PSScriptRoot\..\Templates\LICENSE\" | |
| # Get the list of folders | |
| $Folders = Get-ChildItem -Path $ParentDirectory -Directory |
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 Scan-LOLDrivers { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string]$path | |
| ) | |
| Add-Type -TypeDefinition @" | |
| using System; | |
| using System.Security.Cryptography; | |
| using System.Security.Cryptography.X509Certificates; |
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 Set-ADPrincipalRedirection { | |
| param( | |
| [Parameter(Mandatory)] | |
| $Domain, | |
| [string] | |
| $ComputersOU, | |
| [string] | |
| $UsersOU |
NewerOlder