locked
Powershell: icACLs chokes on paths with spaces RRS feed

  • General discussion

  • I'm looping through a directory structure and saving the permissions from each directory inside itself using icACLs.exe. I need to use robocopy to find all the paths since the a lot of the full paths exceed 260 characters. Some also include spaces.

    I seem to have this working well enough until it comes to the spaces, then I get-

    icacls.exe : Y:/this/path/has/ spaces /in/it" /save Perms.txt: The filename, directory name, or volume label syntax is incorrect.

    Here is my code:

    robocopy Y:\Public NULL /l /e /nfl /xx /nc /ns /njh | Out-File Y:\results.txt
    $results = Get-Content Y:\results.txt
    ForEach ($sfile in $results) {
        $sfile = $sfile.Trim()
        cd $sfile
        New-Item -Name Perms.txt -ItemType File -force
        icacls.exe "$sfile" /save Perms.txt    
    }

    I've tried containing $sfile in quotes, braces, but I can't seem to get it to run smoothly through them. I've also noticed that all paths with spaces seem to end with a double quote in the error, though I am not sure why. Thoughts?

    Thursday, December 31, 2015 2:42 PM

All replies