This file contains 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
/////////////////////////////////////// | |
////////// BENCHMARK RESULTS ////////// | |
/////////////////////////////////////// | |
// * Summary * | |
BenchmarkDotNet=v0.11.1, OS=Windows 10.0.17134.286 (1803/April2018Update/Redstone4) | |
Intel Core i3-3240 CPU 3.40GHz (Ivy Bridge), 1 CPU, 4 logical and 2 physical cores | |
Frequency=3312801 Hz, Resolution=301.8594 ns, Timer=TSC | |
.NET Core SDK=2.1.402 |
This file contains 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 Invoke-PSNotification { | |
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')] | |
param( | |
[Parameter(Position=0, Mandatory, ValueFromPipeline)] | |
[object[]] | |
$Body, | |
[string] | |
$Summary = 'PowerShell Notification', |
This file contains 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
# allow self-referential definitions | |
[Flags()] | |
enum Food { | |
Apple | |
Banana | |
Celery | |
Grape | |
Fruit = Apple -bor Banana -bor Grape | |
} |
This file contains 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
type TransformToSKColorAttribute() = | |
inherit ArgumentTransformationAttribute() | |
let matchColor name = | |
seq { | |
match name with | |
| knownColor when ColorNames.Contains(knownColor) -> yield ColorLibrary.[knownColor] | |
| clear when String.Equals(clear, "transparent", StringComparison.OrdinalIgnoreCase) -> yield SKColor.Empty | |
| patternString when WildcardPattern.ContainsWildcardCharacters(patternString) -> | |
let pattern = WildcardPattern(patternString, WildcardOptions.IgnoreCase) |
This file contains 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 Test-PasswordLeaked { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory, Position = 0, ValueFromPipeline)] | |
[PSCredential] | |
$Credential | |
) | |
begin { | |
$SHA1 = [System.Security.Cryptography.SHA1Managed]::new() | |
} |
This file contains 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
$LiveCred = Get-Credential | |
$Results = Invoke-Command -ComputerName ComputerA -ScriptBlock { | |
[PSCustomObject]@{ | |
IP = Get-NetIPConfiguration | | |
Where-Object { $_.IPv4DefaultGateway -and $_.NetAdapter.Status -ne "Disconnected" } | | |
ForEach-Object { | |
$_.IPv4Address.IPAddress | |
} | |
LastBoot = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime |
This file contains 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
#Requires -Modules ThreadJob | |
using namespace System.Collections.Generic | |
function Invoke-AutoCrop { | |
<# | |
.SYNOPSIS | |
Uses the Python AutoCrop tool to crop images down to faces found in the image. | |
.DESCRIPTION | |
Using the AutoCrop tool, images are stripped down to just detected faces and either saved over the original |
This file contains 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
$PrimeNode = nslookup dockerhost.mycorp.com 192.168.31.67 | | |
Select-String -Pattern Address | | |
Where-Object LineNumber -eq 5 | | |
ForEach-Object { $_.Line.Split(' ')[-1] } | |
$SshData = ssh -q docker@$PrimeNode "cat /dns/zones/db.192.168.169" | | |
Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}" | |
$IPList = $SshData -split '; ' | Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}" |
This file contains 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
$Number = 11 | |
$Property = [PSNoteProperty]::new("IsNumber", $true) | |
$Number.PSObject.Properties.Add($Property) | |
$Number # Gives back 11, as you'd expect | |
$Number | Format-List -Force # shows the hidden property | |
#Bonus: ScriptProperties can use $this to refer to the object they're attached to | |
$Number = 7 | |
$AnotherNumber = 42 |
This file contains 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
# Simple approach - let PS's type conversion logic handle it. | |
# Pitfall: someone can just supply arbitrary text to the function, which is a bit unfortunate. | |
function Get-Factorial { | |
param($Number) | |
if ($Number -eq 0) { | |
1 | |
} | |
else { |