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
$Threshold = 100 # => Number of threads running | |
[int[]] $PortsToScan = 80, 443, 125, 8080 | |
[string[]] $HostsToScan = 'google.com', 'cisco.com', 'amazon.com' | |
function Test-TCPPort { | |
[cmdletbinding()] | |
param( | |
[parameter(Mandatory, Valuefrompipeline)] | |
[string] $Name, | |
[parameter(Mandatory)] |
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
$Action = { } | |
try { | |
$iss = [initialsessionstate]::CreateDefault2() | |
$rs = [runspacefactory]::CreateRunspace($Host, $iss) | |
$rs.Open() | |
$ps = [powershell]::Create() | |
$ps.Runspace = $rs | |
$ps.AddScript($Action).Invoke() | |
foreach ($e in $ps.Streams.Error) { | |
# non-terminating error here |
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
#requires -Module Benchpress | |
# Define the Number of Threads here!!! | |
$threads = 10 | |
# Using this to be sure no test failed | |
$resultGrid = [System.Collections.Generic.List[object]]::new() | |
$ran = [random]::new() | |
$items = 100000 | |
$testArray = while($items--) |
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
#requires -Module BenchPress | |
using namespace System.Collections | |
using namespace System.Collections.Generic | |
Measure-Benchmark -GroupName "Collecting Integers" -RepeatCount 10 -Technique @{ | |
'Implicit Pipeline Result' = { | |
$result = foreach($i in 0..10000) | |
{ | |
$i |
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.Management.Automation | |
using namespace System.Management.Automation.Language | |
using namespace System.Collections | |
using namespace System.Collections.Generic | |
class Completer : IArgumentCompleter { | |
[IEnumerable[CompletionResult]] CompleteArgument( | |
[string]$CommandName, | |
[string]$ParameterName, | |
[string]$WordToComplete, |
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
#requires -version 5 | |
<# | |
.SYNOPSIS | |
High Performance Powershell Module Installation | |
.DESCRIPTION | |
This is a proof of concept for using the Powershell Gallery OData API and HTTPClient to parallel install packages | |
It is also a demonstration of using async tasks in powershell appropriately. Who says powershell can't be fast? | |
This drastically reduces the bandwidth/load against Powershell Gallery by only requesting the required data | |
It also handles dependencies (via Nuget), checks for existing packages, and caches already downloaded packages |
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
#requires -Module BenchPress | |
using namespace System.Collections | |
using namespace System.Collections.Generic | |
$ran = [random]::new() | |
$dataset = foreach($i in 1..100000) { | |
[pscustomobject]@{ | |
Val = $ran.Next(1, $i) |
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.IO | |
function Find-String { | |
param( | |
[parameter(ValueFromPipeline, Mandatory)] | |
[Alias('PSPath')] | |
[FileInfo]$Path, | |
[parameter(Mandatory, Position = 0)] | |
[regex]$Pattern, | |
[switch]$AllMatches, |
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 | |
class PasswordGen { | |
[int] $Length = 20 | |
[int] $NonAlphaCount = 7 | |
[string] $Password | |
PasswordGen () { | |
$this.GetNewPassword() | |
} |
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
$myWeirdParams = @( | |
"-First" | Add-Member -NotePropertyName '<CommandParameterName>' -NotePropertyValue 'First' -PassThru | |
3 | |
,@("name", "fullname") | |
) | |
Get-ChildItem | Select-Object @myWeirdParams |
OlderNewer