The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

franck (17) [Avatar] Offline
hi all
I have a problem with get-acl and square brackets in PathName:

The escape character ` work with get-childitem (example #1) but not with get-acl (example #2)

********** Example #1
PS C:dataETT> gci 'C:Tempstreamsadsspy``[1].zip'

Directory: Microsoft.PowerShell.CoreFileSystem::C:Tempstreams

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 30.01.2007 09:18 30261 adsspy[1].zip

********** Example #2
PS C:dataETT> get-acl 'C:Tempstreamsadsspy``[1].zip'
Get-Acl : Cannot find path 'C:Tempstreamsadsspy[1].zip' because it does not ex
At line:1 char:8
+ get-acl <<<< 'C:TempAnalyse_ToolsADSstreamsadsspy``[1].zip'

i'm trying with get-acl C:Tempstreamsadsspy````[1].zip, but the result is the same.

Best regards Franck
brucepay (155) [Avatar] Offline
Re: Problem with square brackets and get-acl (no -literalpath)
This is an unfortunate bug in the Get-Acl cmdlet where pathnames are going through wildcard resolution twice. The first time through, the quotes are processed and the file match succeeds. Unfortunately wildcard processing is done a second time while retrieving the security descriptor and this time the call fails because the quotes were removed during the first phase. It's an unfortunate bug because there are no easy workarounds. You'll have to use .NET to get the ACLs. A function like the following should hopefully make this less painful:

function Get-FileAcl ($path)
$rpath = (Resolve-Path $path).path
if ([System.Io.Directory]::Exists($rpath))
new-object System.Security.AccessControl.DirectorySecurity $rpath,all
new-object System.Security.AccessControl.FileSecurity $rpath,all

franck (17) [Avatar] Offline
Re: Problem with square brackets and get-acl (no -literalpath)
Hi Bruce

Thanks a lot

I love Powershell and your book is fantastic