title: PowerShell Search-Mailbox Search Query Troubles
body: <p>Attempting my hand at some PowerShell scripting. I would like to remove Voice Messages from Inbox's after a certain period of time. The code gets all mailboxes within an organization and pipes them to a Search-Mailbox. Then I need to query the mailboxes using the <code>-searchquery</code> option. It does not seem to like how I am placing the Date variable into the query.</p>
  
  <pre><code>$Date = (Get-Date).AddDays(-19)
  $Test = $Date.toString("MM/dd/yyyy")
  $SB = [scriptblock]::create("Sent: $Test AND Attachment:`"VoiceMessage.wav`"")
  Get-Mailbox | Search-Mailbox -TargetMailbox "Example" -TargetFolder "Searching" -SearchQuery $SB -LogOnly -LogLevel Full
  </code></pre>
  
  <p>Edit 1: PowerShell is stating the following when the script is executed:</p>
  
  <blockquote>
    <p>Search-Mailbox : The input object cannot be bound to any parameters
    for the command either because the command does not take pipeline
    input or the input and its properties do not match any of the
    parameters that take pipeline input. At line:3 Char:25</p>
  </blockquote>
  
  <p>Edit Two: Adjusted the Code in my question to the code that works. Thanks for all the help everyone!</p>