Ask Jeff - February 2024
Here we are the end of a quick month. I think the migration issues are behind us and I hope to get back track with my usual publishing cadence. Here's my monthly PowerShell potluck.
PowerShell 7.4.1
In case you missed it, Microsoft released PowerShell 7.4.1 in January of this year. Want to know what's new? Use PowerShell.
Get-WhatsNew | more
If that command failed for you, then you need to get current. Install the Microsoft.PowerShell.WhatsNew
module from the PowerShell Gallery.
Install-Module Microsoft.PowerShell.WhatsNew
The module has a single command which will display the latest release notes for the version of PowerShell you are running. If you run Get-WhatsNew
in Windows PowerShell you'll get 5.1 release notes. In PowerShell 7, you'll get the latest PowerShell 7 release notes. The output is a markdown document. Here a few highlights that I think you'll find helpful.
Breaking Changes
- Added the ProgressAction parameter to the Common Parameters
- Update some PowerShell APIs to throw ArgumentException instead of ArgumentNullException when the argument is an empty string ([#19215][19215]) (Thanks @xtqqczze!)
- Remove code related to
#requires -pssnapin
([#19320][19320]) - Output from
Test-Connection
now includes more detailed information about TCP connection tests
Module changes
PowerShell 7.4 includes Microsoft.PowerShell.PSResourceGet v1.0.1. This module is installed side-by-side with PowerShellGet v2.2.5 and PackageManagement v1.4.8.1. For more information, see the documentation for Microsoft.PowerShell.PSResourceGet).
PowerShell 7.4 now includes PSReadLine v2.3.4. For more information, see the documentation for PSReadLine.
Plus, there are a ton of enhancements and improvements. You can also read the the release notes online.
Get-WhatsNew -Online
CD Tricks
I think I've covered this before, but a reader asked about it so I thought I'd provide a quick recap. In PowerShell, you can use legacy console navigation commands. You can use cd
to change directories.
PS C:\>
PS C:\> cd work\demos
In this context, cd
is an alias for Set-Location
. You can use cd
to navigate to a relative location. Use ".." to navigate up one level.
PS C:\work\demos> cd ..
PS C:\work>
Or navigate to a relative location.
PS C:\work> cd ..\Scripts\PSWorkItem\
PS C:\Scripts\PSWorkItem>
PS C:\Scripts\PSWorkItem> cd docs
PS C:\Scripts\PSWorkItem\docs> cd ..\..\PSProjectStatus\
PS C:\Scripts\PSProjectStatus>
In PowerShell 7, we have a few more tricks. You can use cd -
and cd +
to navigate between locations.
PS C:\work>
PS C:\work> cd .\demos
PS C:\work\demos>
PS C:\work\demos> cd d:\temp
PS D:\temp> cd -
PS C:\work\demos> cd +
PS D:\temp> cd -
PS C:\work\demos> cd -
PS C:\work> cd -
PS C:\Scripts\PSProjectStatus>
Remember to put a space between cd
and the -
or +
symbol.
Get-MyFolderItem
I spend my entire day working from a PowerShell prompt. Over the years I have built many tools and shortcuts to speed my work and make me more efficient. I am constantly looking at directory listings, and often I want to know what are the most recently modified files or directories. At first, I tried a proxy function for Get-ChildItem
but that ended up causing problems with other commands. Instead, I created a new function called Get-MyFolderItem
. This function is a wrapper around Get-ChildItem
and meets my requirements.
Function Get-MyFolderItem {
[CmdletBinding()]
[alias('dl')]
Param(
[Parameter(Position = 0)]
[String]$Path,
[Parameter(Position = 1)]
[String]$Filter,
[Switch]$File,
[Switch]$Directory,
[string[]]$Exclude,
[string[]]$Include,
[Switch]$Recurse
)
#Run Get-ChildItem with whatever parameters are specified.
Get-ChildItem @PSBoundParameters | Sort-Object -Property { -Not $_.PSIsContainer }, LastWriteTime
}
The function uses the same parameters as Get-ChildItem
. I can splat them using PSBoundParameter
. The function then sorts the results by file or directory and then by last write time. I can use the function to get a list of files and directories in a folder, sorted by last write time. I use the dl
alias all the time.
I encourage you to look for ways to make PowerShell work for you.
PSStyle
On March 13, I will be doing a virtual presentation for the PowerShell user group in Rhein Neckar. I'm presenting at a very comfortable 1:00PM Eastern time about how to use PSStyle to enhance your PowerShell work. This will primarily be a PowerShell 7 talk, although there is a PSStyle module you can install in Windows PowerShell to provide a few features.
Even though the meeting is for a German group, I will be presenting in English. You can register on their Meetup site. I assume they will be recording the event. If I get a link I will share it in a future newsletter.
Writing Better PowerShell Code
On April 3, I will present virtually again for the Research Triangle Park PowerShell User Group. My topic is on writing better PowerShell code, based on my years of writing and teaching. I expect I'll be re-visiting ideas first presented to this newsletter. I alway love presenting to this group. It is always lively, engaging, and welcoming. The event hasn't been added to their MeetUp calendar yet, but it will be an evening event usually beginning around 6:30PM Eastern time. Watch social media for registrations links.
PowerShell Summit
The most important item is the upcoming PowerShell+DevOps Global Summit being help April 8-11 in Bellevue, WA. This is the event for PowerShell professionals. I promise this will be the most intense event you ever attend. Not only is the content off-the-chart, the social and community aspects are what people remember. I have yet to meet anyone who said this event was a waste of time and money. If PowerShell is part of your day job, this is the event for you. You can see the schedule here.
Thanks
Thank you as always for your continued support and interest. If you have any questions or comments, feel free to reach me at behind@jdhitsolutons.com or leave a comment on the archived copy of this email.