Skip to content

Instantly share code, notes, and snippets.

Mathias R. Jessen IISResetMe

  • Booking.com
  • Netherlands
View GitHub Profile
@IISResetMe
IISResetMe / Get-HttpRequest.ps1
Last active May 12, 2017
Missing netcat -l in PowerShell
View Get-HttpRequest.ps1
<#
.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 Oct 7, 2014
Speedy PowerShell file search on Windows
View Search-Filename.ps1
<#
.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 Oct 8, 2014
Gather known Tor Exit node IP adresses, useful for traffic blacklisting
View Get-TorExitNodes.ps1
$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 Oct 9, 2014
Implementing map function in PowerShell
View map.ps1
function map
{
param(
[Parameter(Mandatory=$true,Position=0)]
[scriptblock]
$Function,
[Parameter(Mandatory=$true,Position=1)]
[Object[]]
$InputObject
)
@IISResetMe
IISResetMe / LazyWebclient.ps1
Last active Dec 3, 2015
Poor Man's Singleton
View LazyWebclient.ps1
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 Aug 29, 2015
Sanitizes your XML input!
View Repair-XmlString.ps1
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 Aug 29, 2015
Domain vs Forest in Jeff's AD health check
View healthcheck.ps1
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 Nov 9, 2016
Clean out orphaned Group Policy Templates from SYSVOL
View Find-OrphanGPTemplates.ps1
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 Dec 22, 2014
Leverage the power of RegEx!
View Split-DN.ps1
# 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 Dec 30, 2014
PsGetSid local machine SID implementation in PowerShell
View Get-MachineSID.ps1
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
You can’t perform that action at this time.