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 Resolve-Code { | |
| <# | |
| .DESCRIPTION | |
| resolves a command name to its definition, and formats it in a nice way. | |
| also works for classes and dotnet types. | |
| .PARAMETER Code | |
| the code to resolve. can be a command name, a type name, or an object. | |
| .PARAMETER Theme | |
| the TextMate theme to use for formatting. defaults to the current theme. | |
| .EXAMPLE |
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
| class StringMatch { | |
| [String] $File | |
| [int] $Line | |
| [String] $Text | |
| hidden [object] $StringObject | |
| hidden [object] $pipedObject | |
| hidden [string] $FullName | |
| StringMatch(){} | |
| StringMatch([object] $pipedObject, [string]$FullName) { | |
| $this.pipedObject = $pipedObject |
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
| Set-PSReadLineKeyHandler -Chord 'Enter' -BriefDescription 'Replace aliases on enter' -ScriptBlock { | |
| $ast = $tokens = $parseErrors = $cursor = $null | |
| [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState( | |
| [ref]$ast, | |
| [ref]$tokens, | |
| [ref]$parseErrors, | |
| [ref]$cursor | |
| ) | |
| $startAdjustment = 0 | |
| foreach ($token in $tokens) { |
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 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 | |
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)] |
NewerOlder