Skip to content

Instantly share code, notes, and snippets.

View trackd's full-sized avatar
:shipit:
👻🚀

Andree Renneus trackd

:shipit:
👻🚀
View GitHub Profile
@trackd
trackd / PSReadlineAliasReplacement.ps1
Created March 17, 2026 14:20
Replace aliases on enter
Set-PSReadLineKeyHandler -Key 'Enter' -BriefDescription 'Replace aliases on enter' -ScriptBlock {
$cursor = $errors = $tokens = $ast = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState(
[ref]$ast,
[ref]$tokens,
[ref]$errors,
[ref]$cursor
)
$startAdjustment = 0
foreach ($token in $tokens) {
function Invoke-Process {
<#
.DESCRIPTION
Starts a new process and captures its output, error, and exit code.
redirects output and error streams for capturing.
doesnt require redirecting to files like Start-Process.
caveat is you cannot get a window and redirected output at the same time.
for that you need to use Start-Process
@trackd
trackd / ConvertTo-DiscordTime.ps1
Last active December 21, 2025 20:41
Discord time
function ConvertTo-DiscordTime {
<#
.SYNOPSIS
Converts a DateTime to a Discord formatted timestamp.
ShortTime => 21:38
MediumTime => 21:38:23
ShortDate => 12/21/25
LongDate => December 21, 2025
LongDateShortTime => December 21, 2025 at 21:38
@trackd
trackd / IsWindowsTerminal.ps1
Last active December 17, 2025 14:47
IsWindowsTerminal? who knows.
function IsWindowsTerminal {
<#
.SYNOPSIS
this is completely overkill and you should probably not use it.
.NOTES
the problem is:
Start-Process -FilePath powershell -ArgumentList '-nop', '-c', '[bool]$env:WT_SESSION' -RedirectStandardOutput (Join-Path $pwd.Path 'foo.log') -UseNewEnvironment
Start-Sleep 1;Get-Content .\foo.log;Remove-Item .\foo.log
$env:WT_SESSION does not work if you start a shell directly, such as running powershell:
@trackd
trackd / PSWtsapi32.ps1
Created November 7, 2025 09:54
Powershell qwinsta/quser replacement using pinvoke
<#
qwinsta/quser pinvoke thing.
expanded to add Get-WTSClientInfo, Get-WTSInfo, Remove-WTSSession
Get-WTSSessionInfo also grabs a bit more info, specially with -Detailed param.
Based on jborean93's WTSAPI wrapper
https://gist.github.com/jborean93/729410684e8e30f6d79123f0bcd06d9c
<#
# example usage
class foo {
[secret] $thing
[string] $name
}
$test = [foo]@{
thing = [Secret]::new('supersecretthing')
name = 'bob'
function Send-Completion {
<#
https://github.com/microsoft/terminal/wiki/Experimental-Shell-Completion-Menu
#>
[CmdletBinding()]
param()
try {
$a = [char]7 # BEL, `a
@trackd
trackd / New-TableOfContents.ps1
Last active September 6, 2025 23:04
Excel toc generation
function New-TableOfContents {
<#
.EXAMPLE
$excelfile = 'C:\temp\test.xlsx'
$toc = New-TableOfContents -ExcelFile $excelfile
$toc | Export-Excel -Path $ExcelFile -WorksheetName 'TOC' -Title "Table of Contents" -MoveToStart
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
@trackd
trackd / knuth-plass.ps1
Created June 16, 2025 22:13
dont ask me why, i dont know
add-type -TypeDefinition @'
/// knuth plass c# implementation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Knuth;
public static class LB
{
function ConvertTo-DollarWords {
<#
.EXAMPLE
ConvertTo-DollarWords '$1234.56'
ConvertTo-DollarWords '$1234,56'
ConvertTo-DollarWords '$1.01'
#>
param(
[string] $Amount
)