# Get-Childitem exits with "Access is Denied" despite -ea 0

**URL:** <https://forums.powershell.org/t/get-childitem-exits-with-access-is-denied-despite-ea-0/3207>\
**Category:** PowerShell Help\
**Created:** [October 5, 2014, 7:47pm UTC](https://forums.powershell.org/t/get-childitem-exits-with-access-is-denied-despite-ea-0/3207 "2014-10-05T19:47:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kieran-walsh](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@kieran-walsh](https://forums.powershell.org/u/kieran-walsh)\
**Post date:** [October 5, 2014, 7:47pm UTC](https://forums.powershell.org/t/get-childitem-exits-with-access-is-denied-despite-ea-0/3207/1 "2014-10-05T19:47:41Z")

</div>

Hi there,  
I’m running this line to search all ISO files on all drives:  
(GET-WMIOBJECT -query “SELECT \* from win32\_logicaldisk where DriveType = ‘3’”).DeviceID| %{Get-ChildItem -path $\_ -Include \*.ISO -Recurse -Force -ea 0 |Select-Object FullName}

It runs through some drives and list the ISOs that it finds along the way but then exits with this error:

Get-ChildItem : Access is denied  
At line:1 char:92

- … ").DeviceID| %{Get-ChildItem -path $\_ -Include \*.ISO -Recurse -Force -ea 0 |Sele …
- 

```
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```

  - CategoryInfo : NotSpecified: (🙂 [Get-ChildItem], UnauthorizedAccessException
  - FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand

If I expand the error:

PS C:&gt; $error[0]|format-list -force

Exception : System.UnauthorizedAccessException: Access to the path ‘P:\System Volume Information’ is  
denied.  
at [System.IO](http://System.IO).\_\_Error.WinIOError(Int32 errorCode, String maybeFullPath)  
at System.IO.FileSystemEnumerableIterator`1.CommonInit()  
at System.IO.FileSystemEnumerableIterator`1…ctor(String path, String originalUserPath,  
String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean  
checkHost)  
at System.IO.FileSystemEnumerableFactory.CreateDirectoryInfoIterator(String path, String  
originalUserPath, String searchPattern, SearchOption searchOption)  
at Microsoft.PowerShell.Commands.FileSystemProvider.Dir(DirectoryInfo directory, Boolean  
recurse, Boolean nameOnly, ReturnContainers returnContainers)  
TargetObject : P:\System Volume Information  
CategoryInfo : PermissionDenied: (P:\System Volume Information:String) [Get-ChildItem],  
UnauthorizedAccessException  
FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand  
ErrorDetails :  
InvocationInfo : System.Management.Automation.InvocationInfo  
ScriptStackTrace : at , : line 1  
at , : line 1  
PipelineIterationInfo : {0, 1, 0}  
PSMessageDetails :

I can see that I’m not allowed access to “P:\System Volume Information” which I’d expect, but I also expect the ErrorAction of SilentlyContinue to sail past this problem. Any idea why this happens?  
Thanks  
Kieran.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [October 5, 2014, 9:37pm UTC](https://forums.powershell.org/t/get-childitem-exits-with-access-is-denied-despite-ea-0/3207/2 "2014-10-05T21:37:28Z")

</div>

So, first of all, please use “-EA SilentlyContinue” not “-EA 0.” The whole point of the enumeration is to make your code easier to read ;).

Second, -EA only controls what will happen in the event of a non-terminating error. Terminating errors always bail, and you can’t stop it, but you can catch it in a Try/Catch construct. In this case, the cmdlet is throwing a terminating error, I’m guessing. That’s under the control of whoever wrote the cmdlet and the underlying technology - you can’t change that.

---

<div class="post-metadata">

**Author:** ![kieran-walsh](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@kieran-walsh](https://forums.powershell.org/u/kieran-walsh)\
**Post date:** [October 5, 2014, 10:08pm UTC](https://forums.powershell.org/t/get-childitem-exits-with-access-is-denied-despite-ea-0/3207/3 "2014-10-05T22:08:48Z")

</div>

Great stuff Don, didn’t know about the terminating error.  
Thanks for your help!  
Kieran.

---

<div class="post-metadata">

**Author:** ![daniel-krebs](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/daniel-krebs/32/484_2.png) [@daniel-krebs](https://forums.powershell.org/u/daniel-krebs)\
**Post date:** [October 5, 2014, 10:51pm UTC](https://forums.powershell.org/t/get-childitem-exits-with-access-is-denied-despite-ea-0/3207/4 "2014-10-05T22:51:58Z")

</div>

Interesting if I run your line on a computer with WMF 5.0 (September Preview) it works as you’ve expected earlier. Looks like the PowerShell team has changed the behaviour Get-Childitem cmdlet in combination with the -Force switch.

I agree with Don, until we can get our hands on the final of WMF 5.0 bits you’ll need to use the Try/Catch construct.

#Daniel

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:47pm UTC](https://forums.powershell.org/t/get-childitem-exits-with-access-is-denied-despite-ea-0/3207/5 "2024-05-16T20:47:25Z")

</div>

Closed on May 16, 2024, 8:47pm UTC


