PowerShell Round-Up April 2024
Thank you for sticking around for another month. There's always something new to learn. Don't forget that premium subscribers have full access to the archive going back to the beginning of 2022.
As is the routine for the end of the month, I have a potluck of PowerShell tidbits.
Tooling
I think we can all agree that work is much easier when you have the right tool. Here are a few recent tools I've added to my desktop.
Git Sizer
Recently, I was trying to find tools and git examples to help me reduce the size of a repository. I'll be the first to admit that I know enough git to get by. I had been using the hidden .git
folder to to get an idea about the size the repository. Then I came across git-sizer
This is an open source GitHub project you can find at https://github.com/github/git-sizer
This is a compiled standalone executable that runs cross-platform. Download the latest release from https://github.com/github/git-sizer/releases You must be running git
version 2.6 or later.
PS C:\> git --version
git version 2.44.0.windows.1
Put the git-sizer
executable in a folder that is included in %PATH%
. I encourage you to go through the README file in the GitHub repository. Run this to get help at the console.
git-sizer -h
You can quickly check for problems by running the basic command.
PS C:\Scripts\PSScriptTools> git-sizer
Processing blobs: 1633
Processing trees: 426
Processing commits: 144
Matching commits to trees: 144
Processing annotated tags: 0
Processing references: 209
No problems above the current threshold were found
Note that the processing messages are written to the host, not the pipeline. I typically look for more detailed information.
PS C:\Scripts\PSScriptTools> git-sizer -v --no-progress
| Name | Value | Level of concern |
| ---------------------------- | --------- | ------------------------------ |
| Overall repository size | | |
| * Commits | | |
| * Count | 144 | |
| * Total size | 36.2 KiB | |
| * Trees | | |
| * Count | 426 | |
| * Total size | 515 KiB | |
| * Total tree entries | 11.8 k | |
| * Blobs | | |
| * Count | 1.63 k | |
| * Total size | 76.6 MiB | |
| * Annotated tags | | |
| * Count | 0 | |
| * References | | |
| * Count | 209 | |
| * Branches | 5 | |
| * Tags | 68 | |
| * Remote-tracking refs | 1 | |
| * Other | 135 | |
| | | |
| Biggest objects | | |
| * Commits | | |
| * Maximum size [1] | 570 B | |
| * Maximum parents [2] | 2 | |
| * Trees | | |
| * Maximum entries [3] | 101 | |
| * Blobs | | |
| * Maximum size [4] | 3.38 MiB | |
| | | |
| History structure | | |
| * Maximum history depth | 141 | |
| * Maximum tag depth | 0 | |
| | | |
| Biggest checkouts | | |
| * Number of directories [5] | 13 | |
| * Maximum path depth [5] | 3 | |
| * Maximum path length [5] | 45 B | |
| * Number of files [6] | 307 | |
| * Total size of files [5] | 16.2 MiB | |
| * Number of symlinks | 0 | |
| * Number of submodules | 0 | |
[1] d10e4b0a39530a6d49eab20a4e440e9250d8e458 (refs/replace/cf1be05866f69cc1c3088fd080eee3818c532eff)
[2] c6563a37b9cfeb115562aac1be7f9dcf0198376b (refs/replace/9683dde3cd0bcc7e2940a1e7b3063f5746e1753d)
[3] c56714bf01c29099e70e0e2ffd809564d84ff4b6 (refs/heads/2.48.0:docs)
[4] 1f11d6717c29d1893b8ce24ab60cb190f65a83f6 (refs/heads/2.48.0:PSScriptToolsManual.pdf)
[5] 6e18ff602f48b239e53d85c5bfa3ef35e22d0ea2 (refs/heads/2.48.0^{tree})
[6] 66c688c610dbe5529830ee843dc28c659446c3d9 (refs/replace/3b7b4019522c21ab134b9b591adc5d461b715d51^{tree})
I'll confess that I don't understand much of this report. Again, the README file helps decipher the output. But, there are no real issues with this repository so I won't stress too much about it.
If you want to build your own reporting, the tool lets you save the output as JSON.
PS C:\Scripts\PSScriptTools> $g = git-sizer -jv --json-version=2 --no-progress | ConvertFrom-Json
PS C:\Scripts\PSScriptTools> $g.UniqueTreeSize
description : The total size of all distinct tree objects
value : 526977
unit : B
prefixes : binary
referenceValue : 2000000000
levelOfConcern : 0.0002634885
PS C:\Scripts\PSScriptTools> $g.uniqueBlobsize.value/1mb
76.5908994674683
I'm still learning how to best take advantage of this tool, so if you find ways that help you, I hope you'll share your discoveries.
Bottom
Another tool I've started using again is a terminal-based performance monitor called bottom
. This too, is an open-source project you can find at https://github.com/ClementTsang/bottom The project has terrific documentation.
You can install with most package managers. I used winget.
winget install bottom
You can find other installation options in the README file.
The tool is based on Linux commands like htop
. You can get similar output by running:
btm -b
Press Q
to quit.
You can also configure a richer display. In Windows Terminal, I have a profile configured to this command line:
%SystemRoot%\System32\cmd.exe /c btm -Tf --network_use_bytes --color nord --enable_gpu_memory
You can click and navigate your way around the different panels. The program wont' work across a PowerShell remoting session, but it will work over SSH.
Presentation Material
I hope you are taking advantage of user group presentations. It is a great way to get involved with the community and often an excellent way to expose yourself to new content. Here are some recent presentation links you might find helpful.
PowerShell Pet Projects
I did a presentation in November of last year for The PowerShell UserGroup Inn-Salzach. I talked about the PowerShell toolmaking process and reviewed some of my projects. The YouTube recording of that presentation is now available. You can find the code from my presentation in GitHub
RTPSUG
I presented for the Research Triangle PowerShell User Group at the beginning of the month. I talked about writing better PowerShell code. Much of my talk was drawn from content I create in this newsletter. The YouTube recording is not available yet, but my session can material can be found at https://gist.github.com/jdhitsolutions/a2f3a246c929a91e494601fa1c44fa55.
Build Beautiful Docs
Josh Hendricks also presented for RTPSUG on creating documentation for your code using the Platyps module. He also discusses how to use Mkdocs to create a static web site based on your content. The YouTube recording is now online at https://www.youtube.com/watch?v=svqPt3jEPyY
PowerShell Practice Primer
A number of years ago, I published a book on Leanpub designed to help people learn PowerShell. Reading books and documentation is fine, but eventually you need to do it. However, it can be challenging to know what to do. That's why I wrote The PowerShell Practice Primer.
The book has over 100 exercises intended to help you teach yourself PowerShell. The exercises can all be done on a local desktop. Most answers are one or two PowerShell commands. You are not expected to write scripts. The fundamentals apply to either Windows PowerShell or PowerShell 7. The book had a section devoted to PowerShell 7 specifically, and I've added a few more exercises to this part and performed a little code cleanup.
When you purchase a copy, there is an extras zip file you can download with .ps1 formatted versions of the chapters. These file are designed to be opened in VSCode (or the PowerShell ISE) so that you can work on your solutions and save your solutions to the file. You can learn more about the book on Leanpub.com The book is digital and you get free updates to future versions.
To celebrate the new release, I help a random drawing from my premium subscribers and ntspiros has won a free copy.
Summary
Thank you all for your continued support. Next month, we'll continue exploring runspaces, look at some fun things you can do with PSReadline, and more. If there is a topic you would like me to explore, please leave a comment or send me an email at behind@jdhitsolutions.com.