Skip to content

Instantly share code, notes, and snippets.

View santisq's full-sized avatar

Santiago Squarzon santisq

View GitHub Profile
$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)]
@santisq
santisq / basicRunspace.ps1
Created January 7, 2022 01:05
a very basic Runspace blueprint
$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
@santisq
santisq / mt-benchmark.ps1
Last active January 8, 2022 02:46
random multi-threading benchmark
#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--)
@santisq
santisq / collecting-results.ps1
Last active January 8, 2022 17:16
Bench-marking different ways to collect results
#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
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,
@santisq
santisq / ModuleFast.ps1
Created January 13, 2022 04:13 — forked from JustinGrote/ModuleFast.ps1
A high performance Powershell Gallery Module Installer
#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
#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)
@santisq
santisq / Find-String.ps1
Last active February 10, 2022 21:01
search for a regex pattern in files, alternative to Select-String
using namespace System.IO
function Find-String {
param(
[parameter(ValueFromPipeline, Mandatory)]
[Alias('PSPath')]
[FileInfo]$Path,
[parameter(Mandatory, Position = 0)]
[regex]$Pattern,
[switch]$AllMatches,
using namespace System.Collections.Generic
class PasswordGen {
[int] $Length = 20
[int] $NonAlphaCount = 7
[string] $Password
PasswordGen () {
$this.GetNewPassword()
}
$myWeirdParams = @(
"-First" | Add-Member -NotePropertyName '<CommandParameterName>' -NotePropertyValue 'First' -PassThru
3
,@("name", "fullname")
)
Get-ChildItem | Select-Object @myWeirdParams