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
Function Log-Start{
<#
.SYNOPSIS
Creates log file
.DESCRIPTION
Creates log file with path and name that is passed. Checks if log file exists, and if it does deletes it and creates a new one.
Once created, writes initial logging data
.PARAMETER LogPath
@IISResetMe
IISResetMe / Test-NullPerformance.ps1
Last active August 29, 2019 15:57
Output suppression and the pipeline
<#
.Synopsis
Performance test for output suppression in PowerShell
.DESCRIPTION
Very basic performance test against different types of output suppression in PowerShell
Increase the value of the Iterations parameter to observe how performance impacts the different methods
@IISResetMe
IISResetMe / MySnippets.ps1
Created April 24, 2015 17:50
Must-have custom ISE snippets
New-IseSnippet -Title '@Calculated Property, Named' -Description "Named calculated property template" -Text '@{ Name = ""; Expression = { } }' -CaretOffset 11
New-IseSnippet -Title '@Calculated Property, Anonymous' -Description "Calculated property template, without a name (For use with Sort-Object and Group-Object)" -Text '@{ Expression = { } }' -CaretOffset 18
@IISResetMe
IISResetMe / passfunc.ps1
Last active September 15, 2021 07:43
Pass function as argument in PowerShell
function Reverse-String {
param(
[string]$instr
)
$chars = $instr.ToCharArray()
[array]::Reverse($chars)
$chars -join ""
}
function New-JunkFile
{
<#
.SYNOPSIS
Generates a file of a specified length, filled with random bytes
.DESCRIPTION
Generates a file of a specified length, filled with random bytes
Uses the RNGCryptoServiceProvider to randomly select each byte
#
# Ping-Forever.ps1
#
# Modified version of alexinnes/ConstantPingToServer.ps1 (https://gist.github.com/alexinnes/b2076c88700020af3963)
#
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$ComputerName,
[string]$LogDirectory = 'C:\ping logs\'
@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 / nullcoalesce.ps1
Last active November 13, 2019 20:57
C#-style Null Coalesce (??) operator
function ?? {
$args |Select-Object -First 1
}
# Use like:
# $Name = ?? (Get-ADUser $_ | Select-Object -Expand Name) "John Doe"
#
# supports as many fallthroughs as you like (like chained ?? in C#)
# $Something =?? $null $null $null 1
# ($Something -eq 1) is now the case
@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