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 / Get-HttpRequest.ps1
Last active March 15, 2022 13:09
Missing netcat -l in PowerShell
<#
.Synopsis
Registers a HTTP prefix and listens for a HttpRequest
.DESCRIPTION
Simple PowerShell HTTP Server implementation to respond to a single HTTP request
.EXAMPLE
Get-HttpRequest -UriPrefix "http://+:80/TestUri/" -ResponseData (Get-Content C:\inetpub\wwwroot\index.html)
.EXAMPLE
Get-HttpRequest -UriPrefix "http://127.0.0.1/" -ResponseData "It Works...!" -ShowRequest
#>
@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 / 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 / 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 / Find-OrphanGPTemplates.ps1
Last active November 9, 2016 17:00
Clean out orphaned Group Policy Templates from SYSVOL
gci "\\$(($d=$env:USERDNSDOMAIN))\sysvol\$d\Policies"|?{$_.Name-imatch"^(?<g>\{[A-F\d]{8}(-[A-F\d]{4}){3}-[A-F\d]{12}\})$"}|?{[ADSI]::Exists("LDAP://CN=$($Matches["g"]),CN=Policies,CN=System,DC=$($d-split"\."-join",DC=")")}|%{"{0} is an orphan, remove it"-f$_.FullName}
@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"(?<=[^\\]),"
@IISResetMe
IISResetMe / Get-MachineSID.ps1
Created December 30, 2014 15:40
PsGetSid local machine SID implementation in PowerShell
function Get-MachineSID
{
param(
[switch]
$DomainSID
)
# Retrieve the Win32_ComputerSystem class and determine if machine is a Domain Controller
$WmiComputerSystem = Get-WmiObject -Class Win32_ComputerSystem
$IsDomainController = $WmiComputerSystem.DomainRole -ge 4