Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell Helper Scripts for Windows Terminal

Posted on May 1, 2020May 5, 2020

I've spent some time over the last few days getting my Windows Terminal setup in order. Hopefull you saw my recent post about backing up my settings.json file. I've also put together a few other simple PowerShell scripts that I use to make Windows Terminal even easier to use and manage.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

Track Version

One of the challenges is that Windows Terminal can silently update automatically. On hand, I appreciate that. But, this also means I'm missing out on knowing about changes I might need to know about. My profile settings were a mess because I didn't keep on top of changes. So I fixed that.

Because I run my daily PowerShell 7 session in Windows Terminal that seemed like a good place to start. Although, the script will also work in Windows PowerShell 5.1. The idea is to store the current version number somewhere. I decided to create a json file stored in $Home. The script will check the currently installed version against the stored, previous version. If the current version is newer, I get a message AND my browser opens to the Releases page on GitHub so I can see what is new. Here's the script.

#Track-WTVersion.ps1

#get the currently installed application
$pkg = Get-AppxPackage -Name Microsoft.WindowsTerminal

#get the version numbert
[version]$current = $pkg.Version

#check for previous version file
$verFile = Join-Path -path $home -ChildPath wtver.json

if (Test-Path $verfile) {
    #compare versions
    $in = (Get-Content -Path $verFile | ConvertFrom-Json)
    $previous = $in.VersionString -as [version]
    # Write-Host "Comparing stored version $previous with current version $current" -ForegroundColor cyan
    If ($current -gt $previous) {
        Write-Host "A newer version of Windows Terminal has been detected." -ForegroundColor Yellow
        #view release notes in your default browser
        Start-Process https://github.com/microsoft/terminal/releases
    }
    else {
     #   Write-Host "Windows Terminal is up to date." -ForegroundColor Green
    }
}

#create the json file, adding the version as a string which makes it easier to reconstruct
$current | Select-Object *, 
@{Name = "VersionString"; Expression = {$_.tostring()}},
@{Name="Date";Expression={(Get-Date).DateTime}} |
ConvertTo-Json | Out-File -FilePath $verfile -Encoding ascii -Force

In my PowerShell profile script, if I detect that I'm running in Windows Terminal I run this script.

#If in Windows Terminal
    if ( $env:wt_session) {
        #dot source my custom prompt function
        . C:\scripts\ps7terminal-prompt.ps1
        #check if there is a new version of Windows Terminal
        C:\scripts\Track-WTVersion.ps1
    }

Whenever I start a new PowerShell session if the Windows Terminal version is changed, I am notified.

Open Defaults

Windows Terminal uses a defaults.json file that you can override with your own settings.json. Or put another way, the files are essentially merged with settings.json "winning" any conflicts. My challenge was wanting to know what is in the defaults file, especially with regards to keybindings. I wrote this very short script to launch the file.

#Open-WTDefaults.ps1

# a simple script to open the defaults.json file for Windows Terminal using
# the assoociate application for json files

$json = Join-Path -path (Get-AppxPackage Microsoft.WindowsTerminal).InstallLocation -ChildPath defaults.json
if (Test-Path $json) {
    Invoke-Item $json
}
else {
    Write-Warning "Could not find default.json file."
}

Because I am using Invoke-Item, the file will open with the associated application. For most of you that will probably be VS Code. You don't want to edit this file. But this makes it easy to open it up and view.

Get Windows Terminal Processes

The last script came out of an issue I read on the Windows Terminal GitHub repository. A comment was made around memory usage. I was curious and came up with this very short script that gets the Windows Terminal process and all of its child processes.

#requires -version 7.0
#Get-WSProcess.ps1

#get the Windows Terminal process and its children
[cmdletbinding()]
Param()

Get-Process -name WindowsTerminal -OutVariable main
Write-Verbose "Getting processes related to $($main.id)"
(Get-Process).Where({$_.parent.id -eq $main.id})

I'm sure there's more than one way to do this but this works fine for me.

wtprocess

Update: I was doing some more testing and this version of the script only works in PowerShell 7.

I hope you find these as handy as I do. As usual, questions and comments are welcome.


Behind the PowerShell Pipeline

Update 2: These code samples are now part of the WTToolbox module.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d