Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use PowerShell's get-acl cmdlet when a filename contains brackets?
    text
    copied!<p>Suppose I have a file named "test[1].txt". Both of these commands produce no output:</p> <pre><code>PS C:\Temp&gt; dir test[1].txt PS C:\Temp&gt; get-acl test[1].txt PS C:\Temp&gt; </code></pre> <p><br /> The good news is that the <code>dir</code> command has a <code>-LiteralPath</code> switch that tells it not to interpret any characters as wildcards:</p> <pre><code>PS C:\Temp&gt; 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 </code></pre> <p><br /> The bad news is that <code>get-acl</code> has no such switch. This appears to be a known <a href="https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=386138&amp;SiteID=99" rel="nofollow noreferrer">issue</a>.</p> <p>The only workaround I could come up with, following an observation in that report, is to use UNC paths in this somewhat awkward way:</p> <pre><code>PS C:\Temp&gt; get-acl \\mymachine\C$\temp\test[[]1[]].txt Directory: Microsoft.PowerShell.Core\FileSystem::\\mymachine\C$\temp Path Owner ---- ----- test[1].txt MYDOMAIN\myname </code></pre> <p>I'm using get-acl in a pipeline fed by <code>dir -rec -name</code>. 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.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload