This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| # example usage | |
| class foo { | |
| [secret] $thing | |
| [string] $name | |
| } | |
| $test = [foo]@{ | |
| thing = [Secret]::new('supersecretthing') | |
| name = 'bob' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Send-Completion { | |
| <# | |
| https://github.com/microsoft/terminal/wiki/Experimental-Shell-Completion-Menu | |
| #> | |
| [CmdletBinding()] | |
| param() | |
| try { | |
| $a = [char]7 # BEL, `a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConvertTo-DollarWords { | |
| <# | |
| .EXAMPLE | |
| ConvertTo-DollarWords '$1234.56' | |
| ConvertTo-DollarWords '$1234,56' | |
| ConvertTo-DollarWords '$1.01' | |
| #> | |
| param( | |
| [string] $Amount | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Write-ProgressBar { | |
| <# | |
| .NOTES | |
| 0 is the default state, and indicates that the progress bar should be hidden. Use this state when the command is complete, to clear out any progress state. | |
| 1: set progress value to <progress>, in the "default" state. | |
| 2: set progress value to <progress>, in the "Error" state | |
| 3: set the taskbar to the "Indeterminate" state. This is useful for commands that don't have a progress value, but are still running. This state ignores the <progress> value. | |
| 4: set progress value to <progress>, in the "Warning" state | |
| <progress> is a number between 0 and 100, inclusive | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Enable-SSH { | |
| [cmdletbinding(SupportsShouldProcess, ConfirmImpact = 'High')] | |
| param() | |
| # could just set it to require administrator but that gets annoying if including it in a module. | |
| $CurrentScope = [Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()) | |
| if (-Not $CurrentScope.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
| $PSCmdlet.ThrowTerminatingError( | |
| [System.Management.Automation.ErrorRecord]::new( |
NewerOlder