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 / Set-ADPrincipalRedirection.ps1
Created November 22, 2022 14:35
Quick and dirty function to affect the same changes as redircmp.exe and redirusr.exe
function Set-ADPrincipalRedirection {
param(
[Parameter(Mandatory)]
$Domain,
[string]
$ComputersOU,
[string]
$UsersOU
function ConvertFrom-WildcardPattern {
param(
[Parameter(Mandatory, ValueFromPipeline)]
[WildcardPattern]$InputObject
)
begin {
$pctrProp = [WildcardPattern].
GetMember('PatternConvertedToRegex', [Reflection.BindingFlags]'NonPublic, Instance')
}
@IISResetMe
IISResetMe / ToastNotification_Windows10.ps1
Last active September 3, 2022 15:06 — forked from altrive/ToastNotification_Windows10.ps1
Windows 10 toast notification sample
function New-ToastNotification
{
param(
[Parameter(Mandatory=$true)]
[string]$Title,
[Parameter(Mandatory=$false)]
[string[]]$Message,
[Parameter(Mandatory=$false)]
@IISResetMe
IISResetMe / BigIntRange.class.ps1
Created August 13, 2019 15:38
Lazy range generator for `[bigint]`
class BigIntRange : System.Collections.IEnumerable
{
[bigint]$from
[bigint]$to
[bool]$Descending
BigIntRange([bigint]$from,[bigint]$to)
{
$this.from = $from
@IISResetMe
IISResetMe / MagicNumber.class.ps1
Created December 19, 2020 21:18
ECMA-335 SpecialName-based operator overloading in PowerShell classes
class MagicNumber
{
hidden [int] $_value
MagicNumber([int]$value)
{
$this._value = $value
}
# ECMA-335 I.10.3.2
@IISResetMe
IISResetMe / Get-ADCertificateAuthority.ps1
Last active March 23, 2022 17:52 — forked from awakecoding/Get-ADCertificateAuthority.ps1
Get-ADCertificateAuthority.ps1
$ConfigurationDN = $([ADSI]"LDAP://RootDSE").ConfigurationNamingContext;
$SearchRoot = "LDAP://CN=Enrollment Services,CN=Public Key Services,CN=Services,$ConfigurationDN"
$SearchFilter = "(objectCategory=pkiEnrollmentService)"
foreach($CAEnrollService in (New-Object adsiSearcher([ADSI]$SearchRoot,$SearchFilter)).FindAll()){
$serviceProperties = [ordered]@{}
foreach($propName in 'Name CN DnsHostName'.Split()){
$serviceProperties[$propName] = $CAEnrollService.Properties[$propName] |Select -First 1
}
@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 / Get-AuditPolicy.ps1
Last active January 11, 2022 10:53
Poor man's audit policy parser
#Requires -Version 5
# Define AuditSetting enum
[System.Flags()]
enum AuditSetting {
None = 0
Success = 1
Failure = 2
All = 3
}
Get-PSReadLineOption |Get-Content -LiteralPath { $_.HistorySavePath } |ForEach-Object {
if($_.EndsWith('`')){
$last += "{0}`r`n" -f $_.Remove($_.Length - 1)
}else{
"${last}${_}"
$last = $null
}
} |Where-Object {$_ -like '*::*'} |ForEach-Object {
# parse history entry as powershell script
using namespace System.Reflection
using namespace System.Reflection.Emit
using namespace System.Runtime.CompilerServices
# We'll attempt to construct a subset of the functionality of:
# public record TestRecord(int M1, string M2);
#
# Namely, we'll generate:
# - property getters (`get_M1()`, `get_M2()`),
# - a public constructor (`TestRecord(int, int);`),