title: How Do I Catch by FullyQualifiedErrorId in PowerShell?
body: <p>I have a script that creates new AD Objects (via New-ADObject, as it happens). If the object already exists, I need to catch and handle that. However, the exception type isn't nearly as explicit as the FullyQualifiedErrorId. Observe the below:</p>
  
  <pre><code>&gt; $Error[-1] | Format-List -Property * -Force
  
  writeErrorStream      : True
  PSMessageDetails      : 
  Exception             : Microsoft.ActiveDirectory.Management.ADException: An attempt was made to add an object to the directory with 
                      a name that is already in use ---&gt; System.ServiceModel.FaultException: The supplied entry already exists.
                         --- End of inner exception stack trace ---
                         at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForExtendedError(String 
                      extendedErrorMessage, Exception innerException)
                         at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowExceptionForFaultDetail(FaultDetail 
                      faultDetail, FaultException faultException)
                         at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowException(AdwsFault adwsFault, FaultException 
                      faultException)
                         at Microsoft.ActiveDirectory.Management.AdwsConnection.Create(ADAddRequest request)
                         at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSy
                      ncOperations.Add(ADSessionHandle handle, ADAddRequest request)
                         at Microsoft.ActiveDirectory.Management.ADActiveObject.Create()
                         at Microsoft.ActiveDirectory.Management.Commands.ADNewCmdletBase`3.ProcessRecordOverride()
                         at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.ProcessRecord()
  TargetObject          : ou=Domain Controllers,DC=cryotest,DC=testdom
  CategoryInfo          : NotSpecified: (ou=Domain Contr...test,DC=afcdom1:String) [New-ADObject], ADException
  FullyQualifiedErrorId : An attempt was made to add an object to the directory with a name that is already in 
                      use,Microsoft.ActiveDirectory.Management.Commands.NewADObject
  ErrorDetails          : 
  InvocationInfo        : System.Management.Automation.InvocationInfo
  ScriptStackTrace      : at Import-ADObjectOfClass, C:\Users\administrator\Desktop\Import-ADObjects.ps1: line 103
                      at &lt;ScriptBlock&gt;, C:\Users\administrator\Desktop\Import-ADObjects.ps1: line 137
                      at &lt;ScriptBlock&gt;, &lt;No file&gt;: line 1
  PipelineIterationInfo : {1, 1}
  </code></pre>
  
  <p>How can I make use of the more verbose information here in my Catch block?</p>