Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

PS catch Exception

$
0
0

Hallo,

ich bekomme bei dem Cmd (Get-DfsnFolder -Path $dfsFolderPath).Description folgenden Error:

 

Get-DfsnFolder : Cannot get DFS folder properites on "path to share"
At Y:\User\scripts\In Progress\DFS_Report_New.ps1:42 char:10
+ $desc = (Get-DfsnFolder -Path $dfsFolderPath).Description -replace "; ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_DfsNamespaceFolder:Root\Microsoft\...NamespaceFolder) [Get-DfsnFolder], CimException
    + FullyQualifiedErrorId : Windows System Error 1168,Get-DfsnFolder

Get-DfsnFolder : The requested object could not be found.
At Y:\User\scripts\In Progress\DFS_Report_New.ps1:42 char:10
+ $desc = (Get-DfsnFolder -Path $dfsFolderPath).Description -replace "; ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_DfsNamespaceFolder:Root\Microsoft\...NamespaceFolder) [Get-DfsnFolder], CimException
    + FullyQualifiedErrorId : MI RESULT 6,Get-DfsnFolder

Der Error kommt nur bei manchen DFS folder. Ich würde diese gerne mit einem try catch block abfangen und eine Ausgabe in der Konsole machen. Das script soll danach einfach weiterlaufen.

Bisher habe ich folgendes:

try{$desc = (Get-DfsnFolder -Path $dfsFolderPath).Description -replace ";", " "}catch {"Exception caught - Cannot get DFS folder properties on $dfsFolderPath"}

Aber es wird mir trotzdem nur der Error geworfen und nicht die Ausgabe aus dem Catch-Block. 

Danke.



Viewing all articles
Browse latest Browse all 2314

Latest Images

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