The basic idea here is that anything that can produce an image can embed it's output in the terminal now...
Someone on the PowerShell Discord asked about sending a message box to the current user on a computer.
This method should work to query the user for a choice (with an optional timeout) or simply notify them of something, whether the script is being run by the user or by an administrator in a remote PowerShell session, or from system, etc.
It's not thoroughly tested (as with most of what I put on gists), but it does work.
Here's some examples:
Show-RemoteDesktopMessage -Title "Test Message" -Message "This is a test message."
This file contains 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
<# | |
.SYNOPSIS | |
Formats a script file using PSScriptAnalyzer | |
.DESCRIPTION | |
Formats a script file using PSScriptAnalyzer and some hard-coded rules. | |
There are many formatters, but this one is mine. | |
.EXAMPLE | |
Get-ChildItem -Recurse -Filter *.ps1 | Format-ScriptFile | |
#> | |
[CmdletBinding()] |
This file contains 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 Test-Transcribing { | |
[CmdletBinding()] | |
param() | |
$Host.UI.GetType().GetProperty("IsTranscribing",[Reflection.BindingFlags]"NonPublic,Instance").GetValue($Host.UI) | |
} |
This file contains 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
# Borrowed this one from https://github.com/chalk/ansi-regex | |
$script:AnsiPattern = "[\u001b\u009b][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?(?:\u001b\u005c|\u0007))|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))" | |
$script:AnsiRegex = [Regex]::new($AnsiPattern, "Compiled"); | |
function MeasureString { | |
[CmdletBinding()] | |
param( | |
[string]$InputObject | |
) | |
$AnsiRegex.Replace($InputObject, '').Length |
This file contains 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
<# | |
.SYNOPSIS | |
gcixels is like gci, but with sixels... | |
.DESCRIPTION | |
Shows thumbnails of images with titles, directly in terminal. | |
However, it's done with ImageMagick montage, so it's awfully slow. | |
Just sharing it for your inspiration. | |
.NOTES | |
Requires ImageMagick and a Sixel terminal (like Windows Terminal 1.22+ or WezTerm) | |
#> |
This file contains 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
#requires -Modules Metadata | |
function Get-PowerShellConfig { | |
<# | |
.SYNOPSIS | |
Get the PowerShell.config.json as a hashtable | |
.EXAMPLE | |
Get-PowerShellConfig | |
Returns the user's PowerShell Config (usually just what experiments you've enabled) | |
.EXAMPLE |
This file contains 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 Start-Application { | |
param($Name) | |
if (!($Command = @(Get-Command $Name -CommandType Application -ErrorAction Ignore)[0])) { | |
$Command = foreach ($Package in Get-AppxPackage *$Name*) { | |
($Package | Get-AppxPackageManifest).Package.Applications.Application.Executable | % { | |
Join-Path -Path $Package.InstallLocation -ChildPath $_ | |
} | Get-Command | |
} | |
} | |
& $Command |
This file contains 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 Convert-RTTTL { | |
<# | |
.SYNOPSIS | |
Convert Nokia RTTL to VT256 DEC PS (PlaySound) escape sequences for Windows Terminal, for instance. | |
.EXAMPLE | |
Convert-RTTTL 'Mario World Theme:d=4,o=5,b=125:a,8f.,16c,16d,16f,16p,f,16d,16c,16p,16f,16p,16f,16p,8c6,8a.,g,16c,a,8f.,16c,16d,16f,16p,f,16d,16c,16p,16f,16p,16a#,16a,16g,2f,16P,8a.,8f.,8c,8a.,f,16g#,16f,16c,16p,8g#.,2g,8a.,8f.,8c,8a.,f,16g#,16f,8c,2c6' -InformationAction Continue | |
Plays the Mario World Theme song (and show the name in the console). | |
.EXAMPLE | |
Convert-RTTTL 'HauntHouse: d=4,o=6,b=108: 2a5, 2e, 2d#, 2b5, 2a5, 2c, 2d, 2a#5, 2e., e, 1f5, 1a5, 1d#, 2e., d, 2c., b5, 1a5, 1p, 2a5, 2e, 2d#, 2b5, 2a5, 2c, 2d, 2a#5, 2e., e, 1f5, 1a5, 1d#, 2e., d, 2c., b5, 1a5' | Set-Clipboard |
This is barely worth sharing, but you can, for instance, get everything pinned to the taskbar, and unpin it from the start menu
Get-Application -PinnedToTaskbar | UnpinStart
- I can't figure out a way to get the order of the taskbar items...
- Many items don't have the "pin to taskbar" verb when called this way (I don't know why) and you have to do something ridiculous like making a shortcut to them first (thus, the task bar folder) and then pin that.
NewerOlder