title: Powershell Remove Special Character(s) from Filenames
body: <p>I am looking for a way to remove several special characters from filenames via a powershell script.</p>
  
  <p>My filenames look like this:</p>
  
  <p>[Report]_first_day_of_month_01_(generated_by_powershell)_[repnbr1].txt</p>
  
  <p>I have been puzzling over removing the [] and everything between them, the () and everything between those, and removing all the _'s as well, with the desired result being a filename that looks like this:</p>
  
  <p>first day of month 01.txt</p>
  
  <p>Thus far, I have tried the below solution to no avail. I have run each of these from the directory in which the files reside.</p>
  
  <pre><code>Get-ChildItem -Path .\ -Filter *.mkv | %{
  $Name = $_.Name
  $NewName = $Name -Replace "(\s*)\(.*\)",''
  $NewName2 = $NewName -Replace "[\s*]\[.*\]",''
  $NewName3 = $NewName2 -Replace "_",' '
  Rename-Item -Path $_ -NewName $NewName3
  }
  </code></pre>
  
  <p>Since it does not work even if I try and do one set at a time like this:</p>
  
  <pre><code>Get-ChildItem -Path .\ -Filter *.mkv | %{
  $Name = $_.Name
  $NewName = $Name -Replace "(\s*)\(.*\)",''
  Rename-Item -Path $_ -NewName $NewName
  }
  </code></pre>
  
  <p>I assume there is an inherent flaw in the way I am trying to accomplish this task. That being said, I would prefer to use the Rename-Item cmdlet rather than using a move-item solution.</p>