Skip to content

Instantly share code, notes, and snippets.

@jborean93
jborean93 / Add-DebuggableType.ps1
Last active August 20, 2025 12:08
Compiles C# code that can be debugged through a .NET Debugger
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
using namespace Microsoft.CodeAnalysis
using namespace Microsoft.CodeAnalysis.CSharp
using namespace Microsoft.CodeAnalysis.Emit
using namespace Microsoft.CodeAnalysis.Text
using namespace Microsoft.PowerShell.Commands
using namespace System.Collections.Generic
using namespace System.IO
@jborean93
jborean93 / Disable-CertTrustCallback.ps1
Created July 1, 2025 21:40
Various ways of ignoring self signed certificates in Windows PowerShell 5.1
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
using namespace System.Net
using namespace System.Net.Security
Function Disable-CertificateTrust {
[CmdletBinding()]
param ()
@jborean93
jborean93 / Import-PemEncodedRsaKey.ps1
Created June 30, 2025 20:21
Imports a PEM encoded RSA private key in PowerShell, supports PowerShell 5.1
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
using namespace System.IO
using namespace System.Management.Automation
using namespace System.Net
using namespace System.Security.Cryptography
Function Import-PemEncodedRsaKey {
<#
@jborean93
jborean93 / Get-CertificateTemplateInformation.ps1
Last active May 26, 2025 00:54
Gets the Certificate Template Information from an X509Certificate2 object
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
using namespace System.DirectoryServices
using namespace System.Formats.Asn1
using namespace System.Management.Automation
using namespace System.Numerics
using namespace System.Security.Cryptography.X509Certificates
Function Get-CertificateTemplateInformation {
@jborean93
jborean93 / Get-LapsADUpdateTime.ps1
Last active March 25, 2025 07:39
Gets the LAPS UpdateTime attribute for AD computer accounts
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Get-LapsADUpdateTime {
<#
.SYNOPSIS
Gets the Windows LAPS Update Time.
.DESCRIPTION
Gets the Windows LAPS Update Time for the specified computer account. The output value is a DateTime object representing the update time as a UTC date time.
@jborean93
jborean93 / New-ScheduledTaskTrigger.ps1
Created March 21, 2025 05:38
PowerShell script to create a state change, idle, or event trigger
# Copyright: (c) 2025, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function New-CommonTaskTriggerProp {
[OutputType([hashtable])]
[CmdletBinding()]
param (
[Parameter()]
[switch]
$Disable,
@jborean93
jborean93 / GetDiskFreeSpaceExW.ps1
Created March 18, 2025 21:15
Ctypes call to GetDiskFreeSpaceExW
$k32 = New-CtypesLib Kernel32.dll
$free = $total = $totalFree = [int64]0
$res = $k32.SetLastError().GetDiskFreeSpaceExW(
$k32.MarshalAs('C:\', 'LPWStr'),
[ref]$free,
[ref]$total,
[ref]$totalFree)
if (-not $res) {
throw [System.ComponentModel.Win32Exception]::new($k32.LastError)
@jborean93
jborean93 / PSRemoting-over-ssh.md
Created December 12, 2024 00:53
Breakdown over what happens with PSRemoting over SSH

PSRemoting over SSH

Here is the general workflow over a PSRemoting session over SSH, for example spawned with Invoke-Command -HostName foo { 'test' }:

sequenceDiagram
    box Client Machine
    actor C as Pwsh Client
    participant S1 as ssh client
    end
@jborean93
jborean93 / PwshPipeServer.cs
Created December 10, 2024 06:25
Code to run a PowerShell named pipe server as a Task
using System;
using System.Management.Automation.Remoting;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
#nullable enable
/*
This code uses internal APIs of the PowerShell remoting system to create the
@jborean93
jborean93 / AuthenticodeEncoding.Tests.ps1
Last active December 6, 2024 06:23
Pester tests for checking out how the PowerShell Authenticode SIP determines the file encoding for the signature
#Requires -RunAsAdministrator
#Requires -Version 7.4
using namespace System.IO
using namespace System.Formats.Asn1
using namespace System.Globalization
using namespace System.Security.Cryptography
using namespace System.Security.Cryptography.Pkcs
using namespace System.Security.Cryptography.X509Certificates
using namespace System.Text