Skip to content

Instantly share code, notes, and snippets.

Mathias R. Jessen IISResetMe

  • Booking.com
  • Netherlands
Block or report user

Report or block IISResetMe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Get-ADLockedOutUser.ps1
function Get-ADLockedOutUser {
[CmdletBinding(DefaultParameterSetName = 'MultiDC')]
param(
[Parameter(Mandatory = $false, ParameterSetName = 'MultiDC')]
[string[]]$DCFilter = @('*'),
[Parameter(Mandatory = $true, ParameterSetName = 'PDCOnly')]
[switch]$PDCOnly
)
View s_client.ps1
$uri = [uri]'https://www.powershellgallery.com/api/v2/package/Pester/4.10.1'
$client = [System.Net.Sockets.TcpClient]::new($uri.Authority, 443)
try{
$tlsClient = [System.Net.Security.SslStream]::new($client.GetStream())
$tlsClient.AuthenticateAsClient($uri.Authority)
[System.Security.Cryptography.X509Certificates.X509Certificate2]$tlsClient.RemoteCertificate
}
finally{
View lcg.class.ps1
class LCG
{
hidden [long]
$factor = 1140671485
hidden [long]
$offset = 12820163
hidden [long]
$modulus = 16777216
@IISResetMe
IISResetMe / ConvertFrom-EventLogRecord.ps1
Last active Mar 8, 2020
Convert EventData fields from windows event log records to objects
View ConvertFrom-EventLogRecord.ps1
function ConvertFrom-EventLogRecord
{
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[System.Diagnostics.Eventing.Reader.EventLogRecord[]]
$InputEvent,
[Parameter(Mandatory=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string[]]
@IISResetMe
IISResetMe / gist:e0c20ce4fdbab7e19a75255e9d4787d1
Created Nov 26, 2019
Signing XML documents with PowerShell
View gist:e0c20ce4fdbab7e19a75255e9d4787d1
Add-Type -AssemblyName System.Security
function Sign-XML {
Param ( [xml]$xml, [System.Security.Cryptography.X509Certificates.X509Certificate2]$certificate )
[System.Security.Cryptography.xml.SignedXml]$signedXml = $NULL
$signedXml = New-Object System.Security.Cryptography.Xml.SignedXml -ArgumentList $xml
$signedXml.SigningKey = $certificate.PrivateKey
$keyInfo = New-Object System.Security.Cryptography.Xml.KeyInfo
View Get-WebExceptionBody.ps1
function Get-WebExceptionBody
{
param(
[int]$Last
)
if(-not $PSBoundParameters.ContainsKey('Last')){
$Last = 1
}
View Test-WebRequest.class.ps1
using namespace System
using namespace System.Net
using namespace System.Text
using namespace System.IO
class Test
{
# Specify the URL to receive the request.
static Run([string[]]$arguments)
{
@IISResetMe
IISResetMe / nullcoalesce.ps1
Last active Nov 13, 2019
C#-style Null Coalesce (??) operator
View nullcoalesce.ps1
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
View CustomSortedDictionary.ps1
using namespace System.Collections.Generic
# First we define our comparer
class SortPropertyFirstComparer : IComparer[string]
{
[int]Compare([string]$a,[string]$b)
{
if($a -ceq 'Property'){
return -1
}
View MeasureStringAdd.ps1
# download and install https://github.com/IISResetMe/MeasureScript/tree/master/src
Import-Module MeasureScript
Measure-Script -ScriptBlock {# use a stopwatch to measure performance
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
# create a StringBuilder
$text = ""
# appending a string often
You can’t perform that action at this time.