Skip to content

Instantly share code, notes, and snippets.

View IISResetMe's full-sized avatar

Mathias R. Jessen IISResetMe

  • Booking.com
  • Netherlands
View GitHub Profile
@IISResetMe
IISResetMe / objects.ps1
Created September 16, 2015 21:54
Offline comments for Richard Siddaway's Objective: Objects talk @ PSHSummit
#region new()
# new() works not only on PS Classes, but wraps existing .NET ctors as well:
[System.Net.WebProxy]::new("proxyserver.contoso.com",3128)
#endregion
#region Add-Type
#region Access modifiers
@IISResetMe
IISResetMe / Split-VMName.ps1
Created November 12, 2015 23:47
2015 Scripting games puzzle, November
param([string]$VMNameStr)
# Trim whitepsace on input string,
# then split at commas (surrounded by 0 or more whitespace chars on each side)
$VMNameStr.Trim() -split "\s*,\s*"
@IISResetMe
IISResetMe / escapewildcard.ps1
Created November 15, 2015 19:28
Manually escape wildcards
gci Test*|select @{Name="Path";Expression={[regex]::Replace($_.FullName,"\[|\]|\*|\?",{'`{0}'-f$args[0]})}}|gci -Recurse
@IISResetMe
IISResetMe / eDellRoot.ps1
Created November 23, 2015 23:32
Do you trust eDellRoot? Find out with this one-liner!
if((New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 (,[byte[]]@(45,45,45,45,45,66,69,71,73,78,32,67,69,82,84,73,70,73,67,65,84,69,45,45,45,45,45,10,77,73,73,67,56,122,67,67,65,100,43,103,65,119,73,66,65,103,73,81,97,56,86,55,108,82,105,84,113,112,100,76,89,107,114,65,105,80,119,55,116,106,65,74,66,103,85,114,68,103,77,67,72,81,85,65,77,66,81,120,69,106,65,81,10,66,103,78,86,66,65,77,84,67,87,86,69,90,87,120,115,85,109,57,118,100,68,65,101,70,119,48,120,78,84,65,48,77,68,99,120,77,68,73,122,77,106,100,97,70,119,48,122,79,84,69,121,77,122,69,121,77,122,85,53,78,84,108,97,10,77,66,81,120,69,106,65,81,66,103,78,86,66,65,77,84,67,87,86,69,90,87,120,115,85,109,57,118,100,68,67,67,65,83,73,119,68,81,89,74,75,111,90,73,104,118,99,78,65,81,69,66,66,81,65,68,103,103,69,80,65,68,67,67,10,65,81,111,67,103,103,69,66,65,76,51,82,74,103,49,117,122,86,117,69,88,48,72,119,52,88,87,71,122,115,54,111,73,57,87,43,111,55,72,90,100,86,100,66,77,77,86,98,52,71,122,98,52,117,90,106,67,84,78,106,98,80,120,52
@IISResetMe
IISResetMe / Get-AST.ps1
Created December 1, 2015 00:50
PowerShell can parse itself just fine
function Get-AST
{
param(
[Parameter(Mandatory,ValueFromPipeline)]
[psobject[]]$InputObject
)
process{
foreach($Script in $InputObject){
$Tokens = $Errors = @()
@IISResetMe
IISResetMe / SGDec2015.ps1
Created December 9, 2015 02:19
Scripting Games December 2015 puzzle
$list = @"
1 Partridge in a pear tree
2 Turtle Doves
3 French Hens
4 Calling Birds
5 Golden Rings
6 Geese a laying
7 Swans a swimming
8 Maids a milking
9 Ladies dancing
@IISResetMe
IISResetMe / Compare-Arrays.ps1
Last active September 10, 2017 15:42
Array filtering with -like, -contains and hashtables
$array1 = 1..20000
$array2 = 2..2001
$hashtable = $array1 |ForEach-Object -Begin {$t = @{}} -Process {
$t[$_] = $null
} -End {$t}
$eq = Measure-Command {
foreach($i in $array2){
$array1 -eq $i
@IISResetMe
IISResetMe / start-wait.ps1
Created January 29, 2016 18:08
Start-Process -Wait (for the children)
# Child process exe, opens notepad.exe
$null = Add-Type -TypeDefinition 'static class Test{static void Main(string[] args){System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"C:\windows\system32\notepad.exe"));}}' -OutputAssembly child.exe
# Parent process exe, opens child process
$null = Add-Type -TypeDefinition $('static class Test{static void Main(string[] args){System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"' + (Get-Item child.exe).FullName + '"));}}') -OutputAssembly parent.exe
# Wait for Parent to "complete"
$p = Start-Process .\parent.exe -Wait -PassThru
@IISResetMe
IISResetMe / join.vba
Created February 4, 2016 15:25
Better join for Excel
Function Join(InputRange As Range, Optional Separator As String = ",") As String
Dim CurrentRange As Range
Dim FinalString As String
For Each CurrentRange In InputRange
If CurrentRange.Text <> Separator Then
FinalString = FinalString & CurrentRange.Text & Separator
End If
Next
Join = Left(FinalString, Len(FinalString) - Len(Separator))
End Function
@IISResetMe
IISResetMe / Measure-PGNResult.ps1
Last active April 9, 2017 12:24
Parallel PGN result parser with minimal error handling
param(
[parameter(Position=0)]
$ChessFolder = 'D:\iisresetme\ChessData\'
)
# Prepare C# method to read and process the files
$Challenge = @{
Name = 'ResultCounter'
Namespace = 'ChessData'
PassThru = $true