1
Gibt es eine Möglichkeit, diesen Fehler zu unterdrücken. Statt diesen hässlichen und langen Fehler, würde Ich mag Rückgabewert erfassen ($?) Erfolg oder Misserfolg um den BefehlSo unterdrücken Sie die PowerShell-Fehlermeldung während der Variablenzuweisung
PS C:\> $str ="<p> Hi </p>"
PS C:\> $data = [xml]$str
PS C:\> $?
True
PS C:\>
PS C:\> $str ="<p> Hi <p>"
PS C:\> $data = [xml] $str
Cannot convert value "<p> Hi <p>" to type "System.Xml.XmlDocument". Error: "Unexpected end of file has occurred. The following elements are
not closed: p, p. Line 1, position 11."
At line:1 char:1
+ $data = [xml] $str
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastToXmlDocument
PS C:\> $data = [xml] $str 2> $null
Cannot convert value "<p> Hi <p>" to type "System.Xml.XmlDocument". Error: "Unexpected end of file has occurred. The following elements are
not closed: p, p. Line 1, position 11."
At line:1 char:1
+ $data = [xml] $str 2> $null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvalidCastToXmlDocument
PS C:\>
PS C:\> $?
False
PS C:\>
Vielen Dank für die Antwort zu bestimmen. Es funktionierte. –