Вот моя попытка.Это может быть не так кратко, как ответ mklement0 , но я думаю, что он будет делать то, что вы хотите.
Он находит все папки с порядковым номером внутри данного пути (1 уровень) исоздает новые папки с тем же именем, но с большим конечным номером.
$path = 'C:\' #'# (dummy comment to fix broken syntax highlighting)
Get-ChildItem -Path $path -Directory |
Where-Object { $_.Name -match '\d+$' } | # find only folders with a name that ends in a number
Group-Object -Property { $_.Name -replace '\d+$'} | # group these folders by their name without the trailing number
ForEach-Object { # go through all the groups
$baseName = $_.Name # the group name is the base name for the new folder
# get the name of the folder in the group with the highest number
# create a new folder with the same base name and the next sequence number
$lastUsed = ($_.Group | Sort-Object {[int]($_.Name -replace $baseName)} -Descending | Select-Object -First 1).Name
$nextIndex = [int]([regex]'\d+$').Match($lastUsed).Value + 1
$newFolder = Join-Path -Path $path -ChildPath ('{0}{1}' -f $baseName, $nextIndex)
Write-Host "Creating directory '$newFolder'"
New-Item -Path $newFolder -ItemType Directory | Out-Null
}
Поэтому, если у вас есть эти папки в корневом каталоге:
123ABC_1
bar1
foo1
foo2
Результат будет:
123ABC_1
123ABC_2
bar1
bar2
foo1
foo2
foo3