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
$array = 1..10
for ($i = 0; $i -lt $array.Length; $i++) {
Write-Host "Loop iteration $($i + 1): #$($array[$i])"
if ($i -eq $array.Length - 1) { Write-Host "Last loop!" }
}
$array = 1..10
for ($i = 0; $i -lt $array.length; $i++) {
Write-Host "Loop #$($array[$i])"
if ($i = $array.length) { Write-Host "Last loop!" }
}
@IISResetMe
IISResetMe / FullPathHashtable.ps1
Last active January 21, 2025 15:34 — forked from HCRitter/FullPathHashtable.ps1
This PowerShell script creates a hierarchical list of objects with DisplayName, ID, and ParentID properties, organized into three levels. It also builds a HashTable to store these objects and calculates a FullPath property for each object by recursively resolving the hierarchy using the ParentID. The FullPath represents the hierarchical path fro…
# Define the list of objects
$objects = @(
# Level 1
[PSCustomObject]@{ DisplayName = "Root1"; ID = 1; ParentID = $null }
[PSCustomObject]@{ DisplayName = "Root2"; ID = 2; ParentID = $null }
# Level 2
[PSCustomObject]@{ DisplayName = "Child1.1"; ID = 3; ParentID = 1 }
[PSCustomObject]@{ DisplayName = "Child1.2"; ID = 4; ParentID = 1 }
function Get-AvailableLicenseTemplates {
[CmdletBinding()]
param ()
process {
Write-Host "`$PSScriptRoot:" $PSScriptRoot -ForegroundColor Green
# Define the parent directory containing the folders
$ParentDirectory = "$PSScriptRoot\..\Templates\LICENSE\"
# Get the list of folders
$Folders = Get-ChildItem -Path $ParentDirectory -Directory
@IISResetMe
IISResetMe / Scan-LOLDrivers.ps1
Created May 19, 2023 17:08 — forked from MHaggis/Scan-LOLDrivers.ps1
it works - but use with caution :) it's a bit noisy and I think it's broken
function Scan-LOLDrivers {
param(
[Parameter(Mandatory = $true)]
[string]$path
)
Add-Type -TypeDefinition @"
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
@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
}
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Management.Automation.Internal;
using System.Management.Automation.Language;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
@IISResetMe
IISResetMe / ghetto_PowerShell_OOP_sloooooow.ps1
Last active October 11, 2017 15:39
A pipeline-heavy twist on a unique PowerShell coding style seen by a threat actor. This is probably as close to OOP PowerShell as you could get in the PSv2 days.
$MyObject = "" |Select-Object _prop1,_prop2
$MyObject |Add-Member -Name Prop1 -MemberType ScriptProperty -Value {return $this._prop1} -SecondValue {param([int]$value) $this._prop1 = $value}
$MyObject |Add-Member -Name Prop2 -MemberType ScriptProperty -Value {return $this._prop2} -SecondValue {param([int]$value) $this._prop2 = $value}
$MyObject |Add-Member -Name SumProperties -MemberType ScriptMethod -Value { return $this.Prop1 + $this.Prop2 }
$MyObject.Prop1 = 3
$MyObject.Prop2 = 2
$MyObject.SumProperties()
@IISResetMe
IISResetMe / Invoke-SyntaxISEr.ps1
Last active January 9, 2017 00:24 — forked from SadProcessor/Invoke-SyntaxISEr.ps1
ISE Script Explorer - Returns AST/Token/Error
#requires -version 3
#######################################################
#region SyntaxISEr ####################################
## Function Invoke-SyntaxISEr
## BackBone Tool for Invoke-CyberISEr - Exported (?)
<#
.Synopsis
ISE ScriptPane Explorer
@IISResetMe
IISResetMe / Get-RSFileHash.ps1
Last active November 17, 2016 21:19 — forked from rodmhgl/Get-RSFileHash.ps1
Just looking to get input on the best way to handle parameter sets
function Get-RSFileHash {
<#
.Synopsis
Returns an MD5 filehash when given a file path
.DESCRIPTION
Returns an MD5 filehash when given a file path
.EXAMPLE
Get-RSFileHash -Filename c:\temp\filetohash.txt
.EXAMPLE
Get-ChildItem c:\temp\*.txt | get-rsfilehash