Powershell AlphaFS script stops when enumerating a file with insufficient permissions
See original GitHub issueI’m enumerating files recursively and when a file is encountered where I don’t have access to, the scripts stops:
foreach ($file in [Alphaleonis.Win32.Filesystem.Directory]::EnumerateFiles($fullPath,'*',[System.IO.SearchOption]::AllDirectories)){ #Code }
Can result in
(5) Access is denied: [\\?\UNC\some\random\path\*] At somescript.ps1 foreach ($file in [Alphaleonis.Wi ... ~~~~~ CategoryInfo : OperationStopped: (:) [], UnauthorizedAccessException FullyQualifiedErrorId : System.UnauthorizedAccessException
I also can’t seem to trap the error with a simple try catch within the loop, as the issue is when enumerating $file. Doing it afterwards will cancel the loop anyway. Any ideas?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
FYI: Combining flag enum values can be made more readable by using the string parsing PS offers for enums. Something like:
That should at least help a little bit in constraining PS’s sporadic tendency for overly verbose letter salads… 😉 Anyway, later i too will have a beer (or two) in your name, Yomodo! 👍
I think this is what you need: