Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Error handling issue

$
0
0

Hello,

I have a global misunderstanding about error handling. If I start some cmdlet that repeats some steps (classic pipeline for example) and one instance here drops an error but I want to ignore this error why cannot I do this:

    $error.Clear()
    Get-ChildItem ${env:ProgramFiles(x86)} -ErrorVariable $null -ErrorAction SilentlyContinue -Recurse | Where-Object {$_.Name -match "1.exe"} 
    $error[0]

The error always shows:

Get-ChildItem : Access to the path 'C:\Program Files (x86)\Google\CrashReports' is denied.
At line:2 char:5
+     Get-ChildItem ${env:ProgramFiles(x86)} -ErrorVariable $null -Erro ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Program File...le\CrashReports:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>