title: Advanced filter in PowerShell
body: <p>I am trying to use the Excel advanced filter through PowerShell, but I am not having any luck. I can use an autofilter successfully by running the following code:</p>
  
  <pre><code>$rangetofilter = $worksheet2.usedrange.select
  $excel.selection.autofilter(2, "TestFilter")
  </code></pre>
  
  <p>However, I don't understand how to properly convert the syntax given in <em><a href="http://msdn.microsoft.com/en-us/library/office/bb209640(v=office.12).aspx" rel="nofollow noreferrer">Range.AdvancedFilter Method</a></em> to something that PowerShell will accept. For example, I've tried</p>
  
  <pre><code>$excel.selection.AdvancedFilter("xlFilterInPlace", "", "", "TRUE")
  </code></pre>
  
  <p>But I get the following error:</p>
  
  <pre><code>Exception calling "AdvancedFilter" with "4" argument(s): "AdvancedFilter method of
  Range class failed"
  At line:1 char:32
     + $excel.selection.AdvancedFilter &lt;&lt;&lt;&lt; ("xlFilterInPlace","","","TRUE")
     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
     + FullyQualifiedErrorId : ComMethodTargetInvocation
  </code></pre>
  
  <p>So is there a way to run an Excel advanced filter through PowerShell?</p>
  
  <p>I found this: <em><a href="http://gallery.technet.microsoft.com/ScriptCenter/57b497a4-d634-44c6-be5c-ba2699f9961a/" rel="nofollow noreferrer">Delete duplicate rows in excel using advanced filter</a></em>, but it is not working either...</p>