Category Archives: PowerShell

Identify Spurious Windows Reclaimables

OK, then: thanks to some excellent detective work by ElevenForum stalwart @Bree, it looks like DISM can tell curious Windows users which packages are “stuck.” That is, you run the DISM command sequence: Analyze-Clean-Analyze, with a positive number of reclaimable packages still showing. (You can find all the details in my 11/2023 blog post on this topic.) This time around, I’ll show you how to list out the actual items that identify spurious Windows reclaimables. Warning: some PowerShell hacking is involved!

How-to: Identify Spurious Windows Reclaimables

@Bree shows the source for the data needed to identify these strange offenders. It’s based on analyzing data within a DISM generated text file. Here’s the specific command that creates that data:

DISM /ONLINE /GET-PACKAGES /FORMAT:TABLE > KB.txt

What this does is to inspect the current running Windows image (/online), grab all packages it finds with some related data (/get-packages),  and format it into a table (/format:table). That last bit (> KB.txt) redirects command output into that named file. The column headings in that output read: Package Identity, State, Release Type, and Install Time with vertical bars (‘|’) used to separate entries.

Bree’s analysis concurs with my own prior inspection of this same kind of output. We both agree that only lines with the strings “Staged” and “Feature Pack” in them point to spurious Windows packages. His analysis depends on sucking the output into a text file, converting to Excel format, sorting by State, and counting groups of lines to match the spurious reclaimable count to what’s reported by DISM /AnalyzeCompontentStore. Remember: those are packages that stay in the component store even after a DISM /cleanup-image operation has completed successfully. I simply write the output from the /Get-Packages DISM command to a file named KB.txt and filter its results.

Automating Analysis of KB.txt Contents

Next, my PowerShell script comes into play (such as it is, it’s pretty primitive). Unzip kbfilt.zip and then move kbfilt.ps1 to the directory where you created kb.txt (to run this file type .\kbfilt.ps1 inside an administrative PS Terminal window: screenshot follows later).

# Path to the input text file
$inputFilePath = "kb.txt"

# Path to the output text file
$outputFilePath = "kbfilt.txt"

# Read the file line by line and filter the lines
Get-Content $inputFilePath | ForEach-Object {
# Check if the line contains both "Staged" and "Feature Pack"
if ($_ -match "Staged" -and $_ -match "Feature Pack") {
# Output the line to the output file
$_ | Out-File -FilePath $outputFilePath -Append}}

# Confirm the script has finished
Write-Host "Lines w/ 'Staged' and 'Feature Pack' written to $outputFilePath"
Write-Host "Remember to delete kb.txt, kbfilt.txt before next use"

I used the -Append directive for Out-file which means the script appends text to the file and doesn’t over-write (“clobber” in PS-speak) other content. That’s why you’ll want to delete these files if you want to run the script again.

My Copilot+ PC (an Intel Aura Yoga Slim 7 model from Lenovo), running Windows 11 24H2 Build 26100.2134, has 2 spurious packages as shown here:

2 packages with LONG names (typical for Windows)
[Click image to view full-sized.]

This investigation is simply to show you which packages are stuck. You can get rid ofthem with DISM /Remove-Package. But if you do, they’ll most likely pop back up again after you install the next Cumulative Update (CU). Windows images are funny that way. But at least, now you can identify the packages involved.

Facebooklinkedin
Facebooklinkedin

Power Options Get Missing Plans

I was just reading a Ghacks story about enabling the Ultimate Performance plan in Power Options. But when I fired up Control Panel > Power Options, I saw that Lenovo had endowed its killer ThinkPad P16 Gen 1 Mobile workstation with exactly one power plan — namely, Balanced. To make sure Power Options gets missing plans, I had to do a little research and some simple PowerShell command magic. Here goes…

Here’s How Power Options Get Missing Plans

The syntax for adding a Power Plan requires a specific powercfg command to add it to a system — namely

powercfg -duplicatescheme GUID

That makes knowing those GUID (globally unique identifiers) important, so you’ll find those values in the table in the lead-in graphic for all the well-known Windows 10 and 11 Power Plans.

Another handy powercfg command lets you choose the Power Plan you wish to run

powercfg -setactive GUID

To save you any contortions you might otherwise need to get those GUIDs from the lead-in screencap, here’s a list of text values. Cut’n’paste them with my blessing…

Balanced 381b4222-f694-41f0-9685-ff5bb260df2e
High Performance 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
Power Saver a1841308-3541-4fab-bc81-f71556f20b4a
Ultimate Performance 15c9c4f6-8a2b-4a3f-bfcd-6b8d6b8f7e5c

P16 Shows Two — and Only Two — Plans in Power Options

For some odd reason, the P16 Mobile Workstation only shows two Power Plans in Power Options (see screencap below). Of course given that it’s a MOBILE WORKSTATION I simply must run “Ultimate Peformance.” You see the results from that PC next with that peerless Power Plan selected. Basta!

A Mobile Workstation needs Ultimate Performance. Here ’tis!

If I add any plan other than Balanced, it knocks the other one (e.g. High Performance, Power Saver or Ultimate Performance) out of the collection. Indeed powercfg /list only shows the same two that appear in the Power Options screen (like the preceding screencap). Copilot says that’s probably owing to manufacturer overrides (likely), WU items (possible), registry settings (possible), or the presence of modern standby mode (possible).

I now know how to fire up any specific power plan I might want to use, so I’m not inclined to hare off after that range of possibilities. I’ll ask the reviews engineering team at Lenovo about this the next time we chat. If I learn anything useful, I’ll add it to this post. Stay tuned!

Facebooklinkedin
Facebooklinkedin

WinGet Discord Update End-Around

I absolutely love Microsoft’s built-in package manager WinGet. But occasionally things happen when updating application that it can’t (or won’t) handle. As you can see in the lead-in graphic, it cheerfully discloses in red that Discord “…cannot be upgraded using winget.” Indeed, its own built-in update facility did nothing to get me to version 1.0.9165. Thus, my only shot at a WinGet Discord update end-around was the tried-and-true uninstall-reinstall maneuver. That worked, as you can see…

Why Use a WinGet Discord Update End-Around?

Short answer: because it worked. Apparently, it’s uninstaller is smart enough to leave user account information alone. Even though I uninstalled the old version and then installed the new one, it carried over anyway. I’d been worried I’d have to set accounts back up, but no. Everything came up as it should’ve even after an “out-with-the-old, in-with-the-new” operation had completed.

I’m counting myself lucky in this case. There are plenty of other applications that don’t ask if you want to keep personal, account and config info. Then they cheerfully wipe all that stuff out as part of the uninstall process. That makes getting back to where one started a little more time-consuming, especially when a reinstall requires account, password, and possibly even other information to complete.

What’s with Discord’s Pinned Status Anyway?

Notice my attempts to unpin Discord reported “There is no pin for package Discord” (line 7 in the intro graphic). In the past, WinGet has often reported it can’t update Discord because the app is pinned. That’s an experimental feature in WinGet that prevents ordinary syntax for updates from working on certain apps.

Contrary to expectations, though, Discord wasn’t pinned. Yet WinGet couldn’t update it, either. Because the built-in updater didn’t do anything when I tried it (right-click on the notification area icon, then select “Check for updates…” in the resulting pop-up menu), I didn’t have a lot of other options. Thus, I’m grateful that the remove-replace approach did the trick. As you can see from the name of the package downloaded, I did wind up with version 1.0.9165. That’s just what I wanted.

Good thing one can sometimes get lucky here in Windows-World. Glad to have this behind me with no apparent ill effects.

Facebooklinkedin
Facebooklinkedin

WinGet Updates PowerShell, Error Aside

I have to chuckle. There’s a new PowerShell 7.4.4 out. I just used WinGet to update my production PC and it applied the update package. But when it got the end of the update, it reported “Installation abandoned” and ended the WinGet update session. Because 7.4.4 came when I closed, then re-opened, Windows Terminal it looks like WinGet updates PowerShell, error aside. You can see the sequence in the lead-in graphic.

WinGet Updates PowerShell, Error Aside

Notice that a “Cancelled” item shows up below the “Installation abandoned” notification. I’m guessing this last item refers to jumping out of the WinGet update sequence, because you see a normal command line prompt (spiffed up, thanks to Oh-My-Posh).

And sure enough, running WinGet upgrade –all –include-unknown finishes up the remaining items that appeared below PowerShell in the update list. In the next screencap I show a two-pane Windows Terminal session. On the left, you see the sequence of update packages installed; on the right, you see the PS Version is now 7.4.4.

To the left you see WinGet at work; to the right a newly-opened PS session says it’s v7.4.4. [Click image for full-sized view.]

One more thing: the final item in the upgrade sequence on the X1 Extreme was Winget itself (which appears as Microsoft.AppInstaller inside the upgrade list). At its conclusion, WinGet closes things out a bit more reasonably. It says:

Successfully installed. Restart the application to complete the upgrade.

Cancelled

I think that confirms my suspicion that the cancelled item refers to the WinGet session itself. It even throws a couple of Ctrl-C (^C) characters to make sure things get closed out. Here’s a screencap:

Facebooklinkedin
Facebooklinkedin

Update and Check Windows Terminal Versions

When I checked over the PC fleet this morning WinGet let me know an  update for Windows Terminal was pending. It would take the program from version 1.20.11381.0 to 1.20.11781.0. Easy-peasey. But once is was done, I asked myself: what’s the best way to check that the new version is running. Thus, I found myself digging into how to update and check Windows Terminal versions. The lead-in graphic, in fact, shows two ways to version-check, captured from the colorful Lenovo Yoga Slim 7x Copilot+ PC.

For the record those two checks are:

1. Winget list Microsoft.WindowsTerminal shows the current installed version on the PC.
2. Click the down-caret in the WinTerm title bar, then click “About” from the pop-up menu to get the “About” mini-window atop the Windows Terminal application window.

How-to: Update and Check Windows Terminal Versions

The update part is easy using the general WinGet upgrade –all –include-unknown command. But if you want to target WinTerm explicitly, Winget upgrade Microsoft.WindowsTerminal will also work.

One thing to remember, as you’ll see in the next screencap: once you’ve updated Windows Terminal, you need to close the current session, then open a new one. Why? Because the process that’s running the old version won’t quit, and a new process to run the new version won’t take over, until you’ve done the “out with the old, in with the new” routine that this accomplishes. Good stuff!

Update and Check Windows Terminal Versions.ps-details

One more cool little detail: as soon as WinGet updates WinTerm, it bails back out to the command line. That’s so you can close/re-open your session and keep going…

Just another routine day here in Windows-World. I really enjoy working at the command line a LOT more, now that I’ve learned how to jazz things up and make best use of WinGet to keep them current.

Facebooklinkedin
Facebooklinkedin

Font Handling Works Through Settings

OK, then: In the wake of the clean install on the Lenovo ThinkPad P16 Mobile Workstatation, I’ve been reworking some of my runtime stuff. Customizing Windows Terminal comes under that heading, near the top of my priorities. To take proper advantage of OhMyPosh, I have to add a so-called Nerd Font to that PC’s collection. Turns out this is way easy in Windows 11 because font handling works through Settings in that OS. Let me show you!

How Font Handling Works Through Settings

Once upon a time installing fonts in Windows meant visiting the C:\Windows\Fonts directory and dropping the various .ttf (typeface) files there. Then Windows could add them to its collection and display them in a variety of forms in the Control Panel element named Fonts.

And indeed, the Fonts CPL is still alive and well. But if you visit Settings > Personalization > Fonts you see the add fonts window there, with its “Drag and drop to install” instruction. Arguably this is exactly the same at using Control Panel > Fonts. But IMO it’s less work and more fun to use. At least it worked quite well for me.

What Came Out of My Visit to Fonts

Thanks to all the files in my personal account folders and their auto-backup to OneDrive, when I set up a new PC with the same MSA, it inherits all that stuff. So as soon as I visited Nerd Fonts, downloaded CakaydiaCove NF, and installed OhMyPosh on the P16, this is what Windows Terminal looks like (it’s using Jan De Dobbeleer’s eponymous theme named “JanDeDobbeleer” in its config file).

Font Handling Works Through Settings.winfetch

Windows Terminal showing winfetch and OhMyPosh at work, overlaid atop the Nerd Fonts download page. [Click image for full-size view.]

FWIW, I use the various Caskaydia Cove NF (Nerd Font) variants in Windows Terminal because they look great with OhMyPosh. But it’s both worthwhile and fun to poke around that collection to find something that you like and looks as good or better.

Facebooklinkedin
Facebooklinkedin

WinGet Source Hiccup Self-Repair

I saw a new WinGet error message yesterday. In attempting a “blanket update” PowerShell showed a “Failed when opening source(s)…” error instead (see intro graphic above). That same error also suggested its own fix via WinGet source reset. I didn’t read carefully enough to see that the –force option was also required. But my next upgrade attempt succeeded anyway. There was apparently a WinGet Source hiccup self-repair at work. What happened?

OK, Why Did WinGet Source Hiccup Self-Repair?

I can only speculate that there was a transient communications glitch between my test PC and the URLs associated with the Microsoft Store and WinGet itself. To me, this dual drop most likely indicates an interruption of service at the ISP level. Both domains have vastly different IP addresses so it’s unlikely to have been something at their end. Hence my best guess that something affected the lookups from my end through my ISP,  Spectrum.com.

It’s amusing that I discovered this hiccup simply by entering another command (albeit an incorrect one). Upon re-entering the original blanket update:

winget upgrade –all — include-unknown

Everything went through as expected on the second try. Through well-cultivated habits, in fact, my first impulse with Windows when things don’t work as expected is simply to try again and see what happens. In this fragile world of ours (including Windows-World) what doesn’t work at first often succeeds on a subsequent attempt.

Had it turned out otherwise, I’d be showing a different screencap, and telling a different story. This time, second try was the charm!

Facebooklinkedin
Facebooklinkedin

Busy Week Brings 9 WinGet Updates

It’s been a busy week, so I’ve been doing stuff more, and playing less with Windows. How do I know? I just ran WinGet on my production desktop and it tossed up a new personal high. That’s right: my busy week brings 9 WinGet updates to my Windows Terminal PowerShell session. You can see the intro part in the lead-in graphic. Wow!

When Busy Week Brings 9 WinGet Updates, Install Them

So that’s what I’m doing right now, as I write this blog post. The whole 9 items took about 2 minutes to complete. It brought 8 successes and one failure. Because I have numerous M365 components open right now, the M365 Apps for Enterprise install failed. That’s probably because I’m using a different subscription version tied to a different MSA. The one I’m using cheerfully reports itself all caught up.

It’s the one I’m NOT using that reports itself out-of-date (which is perfectly OK, because I’m not using it. Maybe I should remove it?) Isn’t it funny how using multiple MSAs in a Windows PC can occasionally make life interesting when you login with one such account, and use assets tied to another such account?

It’s All Part of Windows’ Inestimable Charms…

Learning where the eccentricities reside or potholes lie, and steering around them, gives me countless opportunities for learning and enjoyment when it comes to working with Windows. But less so than usual this week: I’m busy. In fact, I need to go do some paying work as soon as I’m done here. Cheers!

Facebooklinkedin
Facebooklinkedin

PowerShell Install Goes Cancelled to Abandoned

Here’s a good one. Take a look near the bottom of the lead-in graphic. It shows what happens at the end of a WinGet upgrade sequence with the PowerShell installer. But whereas that installer used to say “Installation cancelled” it now says “Installation abandoned.” Hence my assertion: PowerShell Install Goes Cancelled to Abandoned. In truth, this simply means the Windows Terminal window must be closed and re-opened for a new PowerShell version to take effect.

What PowerShell Install Goes Cancelled to Abandoned Means

Things get interesting when a program that’s currently running gets updated. Generally, for the code to take over from the old, the old must first stop. Then, the new must start up and run, so it can use all of its newly-minted capabilities and capacities. The “cancelled” and “abandoned” stuff is text for an error message that indicates the installer itself had to terminate in some kind of unexpected, unusual, or surprising way.

Look at what comes up when I close Windows Terminal, and then re-open it. Just for grins, I add WinGet list microsoft.PowerShell and another WinGet upgrade … check. The former shows the new version 7.4.2.0 is present (as does the lead-in prompt above it). The latter shows that a new WinGet check no longer reports that PowerShell needs an upgrade. Case closed!

PowerShell Install Goes Cancelled to Abandoned.follow-up

The new PowerShell version is running so it no longer generates an update notification. [Click image full full-size view.]

Facebooklinkedin
Facebooklinkedin

WingetUI Announces UnigetUI Name Change

Though you can use it nicely with the Windows Package Manager, aka WinGet, WingetUI also works with other package managers. As you can see on its GitHub page, WingetUI also works with ScoopChocolateyPipNpm.NET Tool and the PowerShell Gallery. That’s a whole heap of package managers, and helps to explain why WingetUI announces UnigetUI name change in the app right now (see the lead-in graphic for same).

How WingetUI Announces UnigetUI Name Change

When I fired up WingetUI yesterday — for the first time in a couple of weeks, I cheerfully confess — the lead-in graphic popped up on my upstairs Windows 11 test PC (Asrock B550 mobo, Ryzen 5800 CPU, 64 GB RAM, Nvidia 1070TX GPU, etc.). In that little explainer, Marti Climent makes it clear that while WingetUI was initially designed to work only with Winget, it now covers numerous other package managers as well. Hence, the name change.

Of those other package managers, I’ve messed with Scoop and Chocolately. I’ve also turned to PowerShell Gallery on many occasions (though I’d call it a package repository more than a package manager, even though WingetUI/UnigetUI has worked with it for some while now).

WinGet CLI vs. WingetUI/UnigetUI

When I first discovered WingetUI I found it compelling and interesting because I was still learning the intricacies of WinGet commands and their sometimes convoluted syntax. But these days, I’m pretty darn comfortable with WinGet. Thus, I don’t find myself using WingetUI as much as I once did. Nevertheless, it’s a worthwhile tool that’s worth getting to know.

Indeed, I wrote a story about WingetUI for TekkiGurus last August (part of a 4-part Winget series). If you’re curious to learn more about either or both of these topics (Winget and WingetUI/UnigetUI) be sure to check them out. [Note: you’ll find links to the other 3 elements of the WinGet series if you visit the WingetUI story linked above.] Cheers!

Facebooklinkedin
Facebooklinkedin