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 / Search-Filename.ps1
Created October 7, 2014 11:03
Speedy PowerShell file search on Windows
<#
.Synopsis
Performs a basic filename search throughout a directory
.DESCRIPTION
Performs a basic filename search throughout a directory and returns matching file names
.EXAMPLE
Search-Filename -Path "C:\Windows\System32" -Pattern "*.dll"
.EXAMPLE
Search-Filename "document.txt" -Recurse
#>
@IISResetMe
IISResetMe / Get-TorExitNodes.ps1
Created October 8, 2014 13:55
Gather known Tor Exit node IP adresses, useful for traffic blacklisting
$TempFile = [System.IO.Path]::GetTempFileName()
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile("https://check.torproject.org/exit-addresses",$TempFile)
$WebClient.Dispose()
$ExitNodes = Get-Content $TempFile |? {$_ -match "^ExitAddress\b"}
Remove-Item $TempFile -Force
$IPAddr = $ExitNodes |% {($_ -split " ")[1]}
@IISResetMe
IISResetMe / map.ps1
Created October 9, 2014 16:53
Implementing map function in PowerShell
function map
{
param(
[Parameter(Mandatory=$true,Position=0)]
[scriptblock]
$Function,
[Parameter(Mandatory=$true,Position=1)]
[Object[]]
$InputObject
)
@IISResetMe
IISResetMe / Repair-XmlString.ps1
Last active August 29, 2015 14:11
Sanitizes your XML input!
function Repair-XmlString
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[string]$inXML
)
# Match all characters that does NOT belong in an XML document
$rPattern = "[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000\x10FFFF]"
@IISResetMe
IISResetMe / healthcheck.ps1
Last active August 29, 2015 14:11
Domain vs Forest in Jeff's AD health check
param(
...
[Parameter(Mandatory=$false,ParameterSetName='Specific')]
[Parameter(Mandatory=$false,ParameterSetName='All')]
[Switch]$EntireForest
)
function Get-ADDomains {
if($EntireForest)
{
@IISResetMe
IISResetMe / Split-DN.ps1
Created December 22, 2014 17:08
Leverage the power of RegEx!
# Negative lookbehind
function Split-DN{
param([String]$DN)
return $DN-split"(?<!\\),"
}
# Positive lookbehind with negative expression
function Split-DN{
param([String]$DN)
return $DN-split"(?<=[^\\]),"
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 / 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
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\'