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 Measure-ChildItem { | |
<# | |
.SYNOPSIS | |
Recursively measures the size of a directory. | |
.DESCRIPTION | |
Recursively measures the size of a directory. | |
Measure-ChildItem uses win32 functions, returning a minimal amount of information to gain speed. Once started, the operation cannot be interrupted by using Control and C. The more items present in a directory structure the longer this command will take. | |
This command supports paths longer than 260 characters. |
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 Get-MyDisk { | |
[CmdletBinding()] | |
param( | |
[Alias('DeviceId')] | |
[int] $Number, | |
[string] $FriendlyName | |
) | |
if (-Not ('Pinvoke.Win32Utils' -as [type])) { | |
Add-Type -TypeDefinition @' |
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
# Copyright: (c) 2022, Jordan Borean (@jborean93) <[email protected]> | |
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | |
Add-Type -TypeDefinition @' | |
using System; | |
using System.Runtime.InteropServices; | |
namespace Wtsapi32 | |
{ | |
public enum WtsConnectState |
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-MarkdownTable { | |
<# | |
.DESCRIPTION | |
Convert an object to a markdown table. | |
.PARAMETER InputObject | |
The object to convert to a markdown table. | |
.PARAMETER Property | |
The properties to display in the table. |
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 Get-PowershellDLEHint { | |
$iwr = (Invoke-WebRequest 'https://powershelldle.com/').Content | |
$strings = ($iwr | Select-String -Pattern '<div id="answer-char" class="(relative bottom-1)?">\s*[_-]\s*</div>' -AllMatches).Matches.Value | |
$verb, $noun = ($strings -replace '<[^>]+>').Trim() -join '' -split '-' | |
Get-Command | Where-Object { $_.Verb.Length -eq $verb.length -And $_.Noun.Length -eq $noun.length } | |
} |
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 Get-TableData { | |
<# | |
ls | ft | Get-TableData | |
.NOTES | |
https://gist.github.com/Jaykul/9999be71ee68f3036dc2529c451729f4 | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(ValueFromPipeline)] | |
$FormatStartData |
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
Update-TypeData -TypeName '_RegexAnsi' -MemberType ScriptMethod -MemberName ToString -Force -Value { | |
return ($this.Value ? $this.value : $this.Text) | |
} | |
Update-TypeData -TypeName 'System.Management.Automation.Internal.StringDecorated' -MemberType ScriptMethod -MemberName ToString -Force -Value { | |
return $this.IsDecorated | |
} | |
function Get-AnsiEscape { | |
<# | |
.DESCRIPTION | |
Get-AnsiEscape can be used to strip, escape, or regex VT codes from a string. |
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-DebugSpectre { | |
[cmdletbinding()] | |
param() | |
$moduleName = 'PwshSpectreConsole' | |
$module = Get-Module -Name $ModuleName | |
if (-Not $Module) { | |
$Module = Import-Module $ModuleName -PassThru | |
} | |
$new = { | |
param( |
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 Set-DemoPrompt { | |
<# | |
.SYNOPSIS | |
Creates a simple prompt with WT highlighting using a temporary module. | |
minor trickery with setting an alias for prompt so we can easily restore old prompt on module removal. | |
.NOTES | |
it adds terminal prompt markings for WT Preview. | |
see links below for more info | |
.LINK | |
https://learn.microsoft.com/en-us/windows/terminal/tutorials/shell-integration#powershell-pwshexe/ |
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 Add-ClipboardProtocolHandler { | |
# clipboard:// | |
$custom = Get-Command "$env:temp\customclip.exe" -CommandType Application -ErrorAction 'Stop' | |
$uri = 'clipboard' | |
if (!(Test-Path "HKCU:\Software\Classes\$uri")) { | |
New-Item "HKCU:\Software\Classes\$uri" | |
} | |
Set-ItemProperty "HKCU:\Software\Classes\$uri" '(Default)' "URL:$uri Protocol" | |
Set-ItemProperty "HKCU:\Software\Classes\$uri" 'URL Protocol' '' | |
if (!(Test-Path "HKCU:\Software\Classes\$uri\shell")) { |