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 / simplefilterparser.ps1
Created August 4, 2015 17:37
Very frail PowerShell string-filter parser
function Parse-SimpleFilter {
param([string]$Filter)
$err = @() # TODO inspect parsing errors
$Tokens = [System.Management.Automation.PSParser]::Tokenize($Filter,[ref]$err)
$Elements = foreach($t in $Tokens){
switch($t.Type){
([System.Management.Automation.PSTokenType]::Command) {
'$_.{0}' -f $t.Content
@IISResetMe
IISResetMe / Measure-Lines.ps1
Created August 15, 2015 18:05
Count lines in file
function Measure-Lines {
param($Path = 'C:\log.txt')
$FileStream = New-Object IO.FileStream ($Path,[System.IO.FileMode]::Open,[System.IO.FileAccess]::Read,[System.IO.FileShare]::ReadWrite)
$StreamReader = New-Object System.IO.StreamReader $FileStream
$TotalLines = 0
while($StreamReader.ReadLine() -ne $null){
$TotalLines++
}
$TotalLines
@IISResetMe
IISResetMe / SGSept2015.ps1
Last active September 5, 2015 20:49
2015 Scripting Games - September puzzle
# Most straighforward way I can think of
# 2 pairs of curly braces and a single semicolon for the calculated OSVERSION property
Import-Csv .\input.csv |Select-Object -Property MACHINENAME,@{Label='OSVERSION';Expression={(Get-WmiObject Win32_OperatingSystem -ComputerName $_.MACHINENAME).Caption}} | Export-Csv .\output.csv -NoTypeInformation
@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 / LazyWebclient.ps1
Last active December 3, 2015 18:35
Poor Man's Singleton
param($u)(&{if($c-is[System.Net.WebClient]){$c}else{($global:c=New-Object System.Net.WebClient)}}).DownloadString($u)
@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