PowerShell v3 Where-Object Syntax Produces Different Results Than v2 Syntax
I posted a blog yesterday about a PowerShell issue I was experiencing and the problem ended up being
due to the new PowerShell version 3 Where-Object
Syntax producing different results than the
PowerShell version 2 Where-Object
syntax.
Piping Get-Volume
to Where-Object
and filtering on the drive letter using the version 3 syntax
appears to be case sensitive. It doesn't return results when using a lower case 'c':
1Get-Volume | where DriveLetter -eq 'C'
2Get-Volume | where DriveLetter -eq 'c'
Using the PowerShell version 2 syntax with Where-Object
does not appear to be case sensitive. Both
upper and lower case letters return the same results:
1Get-Volume | where {$_.DriveLetter -eq 'C'}
2Get-Volume | where {$_.DriveLetter -eq 'c'}
Yeah, I know Get-Volume
has a DriveLetter
parameter to filter on this without having to use
Where-Object
. See
my previous blog
for more details on how I came to this conclusion.
Just an FYI, I've only tested this on Windows 8.
Update:
Very strange. I've tried this on two other Windows 8 machines and neither one of them have this
issue (they return the same results with either syntax) and I know at least one of them was
installed with the same media. Further investigation to follow. I'll try loading PowerShell with the
-noprofile
option next to make sure nothing in my profile is causing an issue.
µ