Home Dashboard Directory Help

Get-ChildItem and 'Filter' parameter misissue by Vadims Podans



Sign in
to vote
Type: Bug
ID: 675309
Opened: 6/14/2011 5:41:42 AM
Access Restriction: Public
User(s) can reproduce this bug


'-Filter' parameter tries to bind filter pattern to a both general name and a name in the 8.3 notation (MS-DOS format). This causes that in the 'Get-ChildItem -Filter' output appears unexpected items. For details see repro section.

Also this may cause catastrophic results if Get-ChildItem output is passed to Remove-Item cmdlet. Administrator will not expect that Program Files folders will match this pattern. Also PowerShell doesn't have native ways to determine certain object (file or folder) short name in 8.3 notation and returned object doesn't contain related property. This can be done dy running 'dir.exe' with /x switch.

Also documentation has no mention about this behavior.
Sign in to post a comment.
Posted by Microsoft on 1/12/2012 at 4:36 PM
We've added a bunch of new parameters to Where-Object to make it easier to do things like this.
Posted by Stephen Mills on 7/19/2011 at 10:40 AM
I agree that this should be considered a bug. I understand why it is happening, the underlying windows api searches both the short and long filename (FindFirstFile and FindNextFile), since they don't do additional filtering on the results, it leads to the odd results. I think they should filter the results from the Windows API so that it only returns matches based on the long file name.
Sign in to post a workaround.