title: Advance file search with powershell
body: <p>I'm fairly new to Powershell and programming in general. I want to search files using Powershell having multiple conditions. I have managed to write this code</p>
  <pre><code>$Drives = Get-PSDrive -PSProvider 'FileSystem' 
  $Filename= 'Result'
  $IncludeExt= '*csv,*docx'
  $StartDate= '11/1/20'
  $EndDate= '1/26/21'
  
  Get-ChildItem -Path $Drives.Root -Recurse  |Where-Object {$IncludeExt -match $_.Extension} |  Where-Object { $_.BaseName -match $Filename}  | Where-Object {$_.lastwritetime -ge $StartDate -AND $_.lastwritetime -le $EndDate} |
  
  foreach{ 
  $Item = $_.Basename
  $Path = $_.FullName 
  $Type = $_.Extension
  $Age = $_.CreationTime
  
  
  $Path | Select-Object `
      @{n=&quot;Name&quot;;e={$Item}},`        
      @{n=&quot;Created&quot;;e={$Age}},`
      @{n=&quot;filePath&quot;;e={$Path}},`
      @{n=&quot;Folder/File&quot;;e={if($Folder){&quot;Folder&quot;}else{$Type}}}` 
  
  }| Export-Csv D:\FFNew.csv -NoTypeInformation
  </code></pre>
  <p>This works well when the all variables are mentioned. But how do I get this to work when</p>
  <p>Case1: If $Filename is empty then it gives all the files with the mentioned extensions and files modified in Range of dates</p>
  <p>Case2: If $IncludeExt is left empty then it gives all files with the $Filename mentioned, currently it gives only the folders and files modified in Range of dates</p>
  <p>Case 3: If $Filename and $IncludeExt is left empty it gives all the files modified between the $StartDate and $EndDate</p>