title: How to suppress PowerShell error message during variable assignment
body: <p>Is there any way I can suppress this error. Instead of this ugly and long error, I would like to capture return code value($?) to determine success or failure</p>
  
  <pre><code>    PS C:\&gt; $str ="&lt;p&gt; Hi &lt;/p&gt;"
      PS C:\&gt; $data = [xml]$str
      PS C:\&gt; $?
      True
      PS C:\&gt;
      PS C:\&gt; $str ="&lt;p&gt; Hi &lt;p&gt;"
      PS C:\&gt; $data = [xml] $str
      Cannot convert value "&lt;p&gt; Hi &lt;p&gt;" 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:\&gt; $data = [xml] $str 2&gt; $null
      Cannot convert value "&lt;p&gt; Hi &lt;p&gt;" 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&gt; $null
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
          + FullyQualifiedErrorId : InvalidCastToXmlDocument
  
      PS C:\&gt;
      PS C:\&gt; $?
      False
      PS C:\&gt;
  </code></pre>