PowerShell: Bulk-renaming YYYYMMDD to YYYY-MM-DD

$docs = @{Name = "Docs"}
$docs.Path = "FileSystem:\\SERVER\Scanned Documents"

@($docs) | ForEach-Object {
  Get-ChildItem $_.Path | ForEach-Object {
    $item = $_ | Select-Object -ExpandProperty FullName
    $new = $item -replace '\\(\d{4})(\d\d)(\d\d)\s', "\`${1}-`${2}-`${3} "
    if ($new -ne $item) {
      Rename-Item -Path $item -NewName $new
      Write-Host $new
    }
  }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *