title: How to add leading zeros to a batch of file names before a key character using powershell
body: <p>I'm trying to add leading zeros to a batch of file names before an underscore. </p>
  
  <p>e.g.: going from 123_ABC.pdf to 000123_ABC.pdf</p>
  
  <p>The goal is that before the underscore there should be 6 numbers, and I therefore need to add leading zeros.</p>
  
  <p>I have done this before for cases where i needed to add leading zeros to a file name that was pure numbers, which is the below code, but I'm not sure how to adapt it to the scenario above.</p>
  
  <pre><code>Get-ChildItem "[Folder Location]" | ForEach-Object {
      $NewName = "{0:d6}$($_.Extension)" -f [int]$_.BaseName
      Rename-Item $_.FullName $NewName
  }
  </code></pre>
  
  <p>Any help would be really appreciated.
  Thanks</p>