Words: 183
Time to read: ~ 1 minute
A while ago I talked about an issue that I had in Windows PowerShell when I was trying to use the -ExcludeProperty
parameter of Select-Object
.
In case you missed it, it was one of my first posts, you can read it here.
Browsing StackOverflow
Checking out other peoples code is a great way to get exposed to different coding styles and ideas so I like to get a daily email of PowerShell questions from StackOverflow.
In the comments of one of these questions, Michael Klement ( twitter ) pointed out something, a little detail that I didn’t know but really appreciate.
There is a difference between Select-Object
in Windows PowerShell and PowerShell Core
Difference
Let’s take a basic example
Windows PowerShell
# Doesn't work but doesn't work *silently*
[PSCustomObject]@{
Version = $PSVersionTable.PSVersion
Redundant = [Guid]::NewGuid()
} | Select-Object -ExcludeProperty Redundant
# Works
[PSCustomObject]@{
Version = $PSVersionTable.PSVersion
Redundant = [Guid]::NewGuid()
} | Select-Object -ExcludeProperty Redundant -Property *

PowerShell Core
[PSCustomObject]@{
Version = $PSVersionTable.PSVersion
Redundant = [Guid]::NewGuid()
} | Select-Object -ExcludeProperty Redundant

More Intuitive
Sometimes I’m more excited about the little things as I think they are more impactful. I’m excited about this.
The more you know!