PowerShell Potluck: July 2024 Round Up
Once again, the end of another month has snuck up on me. For those of you in the Northern Hemisphere, I hope you're enjoying the summer weather and finding time to relax, recharge, and unplug. Let's wrap up July with a potluck of PowerShell tidbits.
Formatting and Style
This newsletter is delivered primarily to your inbox. A copy is posted in the online archive. Both are formatted with CSS. Over the last month or so, I've been tinkering with the CSS to improve the readability and overall look of the newsletter. I had reports that a few readers were having trouble with the formatting, so I've been working to make it more accessible. It appears the latest Microsoft Outlook client didn't like the CSS I was using. I contacted Buttondown, and they didn't seem too surprised. They have been testing a fix and turned it on for this newsletter. This seems to have solved the problem.
If you have any problem reading the newsletter in your email client, please let me know at behind@jdhitsolutions.com. Tell me the name and version of your email client. A screenshot of the problem would be helpful. Then, check the online archive. You should always be able to read the content there. Again, if not, please let me know.
MVP Status
If you follow me on social media, you probably saw my announcement that I have been recognized for the 18th year as a Microsoft MVP. I am honored to be part of this community. It is thanks to readers like you that I have been able to maintain this status. I intend to continue to provide you with useful and informative content.
Using PowerShell Comments
This item came across my inbox from Petri.com. I encourage you to take a few minutes to read this great article on commenting practices in PowerShell. The commenting syntax is simple, but knowing where and when to comment requires a little more thought.
If you have questions or comments on the article, feel free to leave a comment or drop me a line.
Building PowerShell
Another item to spend a little time with is this podcast with Jeffrey Snover. Even though I've been around PowerShell since the beginning, there are parts to the origin story that I never knew. Jeffrey shares some history about how and why PowerShell came to be, including how it almost wasn't. If you don't have time to listen, there is a transcript on the site you can read. Although, I think you'll appreciate it more listening to Jeffrey.
PSConfEU 2024
And if you can find even more free time, the sessions from this year's PSConfEU held in Antwerp, Belgium, are now available on YouTube. You can find the playlist here. The sessions are all in English. I know much of the content will be high-level and will be content you won't find anywhere else. I'd love to hear what content you find helpful or interesting.
PowerShellRun
I've been testing out a new module called PowerShellRun. The module requires PowerShell 7 and a Windows platform. You can install it from the PowerShell Gallery.
This is an intriguing project. in my opinion, the commands in the module should be treated as a framework for creating a PowerShell-based launcher. I suggest importing the module first.
Import-Module PowerShellRun
Before you can use the Invoke-PSRun
command, you need to define entries. The easiest way to get started is to enable all of the default categories.
Enable-PSRunEntry -Category All
You can also specify a list of categories
- Application
- Script
- Executable
- Favorite
- Function
- Utility
You can find these explained in the project's README
file. I strongly encourage you to read the document as using the module isn't immediately intuitive and command documentation is a work in progress.
Now that I've enabled entries, I can run the launcher.
I have access to all menu shortcuts, programs, and executables found in my path. I can start typing the name of a command and the app will jump to it. You can press Ctrl+K
to open a context menu for any selected item.
You can also add favorite folders.
Add-PSRunFavoriteFolder -Path c:\scripts -Name Scripts -Description "My Scripts and Projects folder"
Or files:
Add-PSRunFavoriteFile -Path $profile.CurrentUserCurrentHost -Name "PSProfile" -Description "CurrentUserCurrentHost"
These are added to the run menu.
These too, will have context menus.
The default editor is whatever is associated with the file extension in the registry, which for a PowerShell file is Notepad by default. But you can add a custom script block.
Add-PSRunScriptBlock -Name "Edit Profile" -ScriptBlock { code $profile.CurrentUserCurrentHost } -Description "Edit PowerShell profile" -Icon '📝'
You could do something similar with a PowerShell script using Add-PSRunScriptFile
. In my configuration, I added an entry for an Excel spreadsheet that I use to schedule this newsletter.
Add-PSRunFavoriteFile -Name PubSchedule -Path $ENV:OneDrive\Behind\PublicationSchedule.xlsx -Description 'Newsletter Schedule' -Icon '🗓️'
This figure shows the Ctrl+k
context menu.
All of this persists for the duration of my PowerShell session. If you start a new session, you need to redefine your entries. I could put all of the commands in my PowerShell profile script. Instead, I created a separate configuration file that defines the entries, as I've shown here, and defines an alias.
Set-Alias -Name psrun -Value Invoke-PSRun
Or, you can add a keybinding.
Set-PSRunPSReadLineKeyHandler -InvokePsRunChord 'Ctrl+Alt+j'
Pressing this key combo will run Invoke-PSRun
.
I'm still testing the module, so I haven't added the configuration file to my profile script. When I'm ready, I'll dot-source it.
. c:\scripts\psrun.ps1
The module also has some fun integrations with Winget and PSReadLine. You might also like the built-in selector.
You can select single or multiple items. To select multiple items, you need the -MultiSelection
parameter. Then press Tab
for each item to select. Pressing Enter
will write the objects to the pipeline
I'm still exploring what I can do with this module and I've posted some questions and issues. I think this project is far from complete, but you can get a lot of benefits from it now. You definitely want to look at the README
file. Since help documentation is minimal, I encourage you to use the repository's Discussion to ask questions and get involved.
Summary
I think that's enough of a round up for this month. There's always something new to learn and explore. That's why have enjoyed PowerShell for the last 18 years. If you find something useful from the content I've shared, I hope you'll share it with your friends and colleagues.
See you next month.