Suppose I have a file named "test[1].txt". Both of these commands produce no output:
PS C:\Temp> dir test[1].txt
PS C:\Temp> get-acl test[1].txt
PS C:\Temp>
The good news is that the dir
command has a -LiteralPath
switch that tells it not to interpret any characters as wildcards:
PS C:\Temp> dir -LiteralPath test[1].txt
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/25/2010 9:57 AM 5 test[1].txt
The bad news is that get-acl
has no such switch. This appears to be a known issue.
The only workaround I could come up with, following an observation in that report, is to use UNC paths in this somewhat awkward way:
PS C:\Temp> get-acl \\mymachine\C$\temp\test[[]1[]].txt
Directory: Microsoft.PowerShell.Core\FileSystem::\\mymachine\C$\temp
Path Owner
---- -----
test[1].txt MYDOMAIN\myname
I'm using get-acl in a pipeline fed by dir -rec -name
. Because I don't know where the wildcards will appear, I'll have to write code to escape them (and convert the paths to UNC format). It's a bit kludgy. Is there a simpler way? I'm using PowerShell v1.0, by the way.
Opinion: Perhaps this is an unavoidable consequence of trade-offs made in the design of PowerShell, but it's unfortunate that every command needs an option to ignore wildcards, rather than having that functionality in the shell itself so that all commands automatically benefit.