How to bulk rename files in a folder

Christopher Jack 1,616 Reputation points
2021-03-12T09:27:44.913+00:00

Hi,

I am requiring to bulk rename some folders in Power shell..

I am trying

rename-Item -Path  (get-childitem "\\server\Elucid\System Reporting\Maginus Reports\Chalgrove\Automated Reports\Current\").fullname -NewName (get-childitem "\\zoom-nas\Elucid\System Reporting\Maginus Reports\Chalgrove\Automated Reports\Current\").fullname + $today

Move-Item -Path  (get-childitem "\\servers\Elucid\System Reporting\Maginus Reports\Chalgrove\Automated Reports\Current\").fullname  -Destination "\\zoom-nas\Elucid\System Reporting\Maginus Reports\Chalgrove\Automated Reports\Archive"

How ever it is failing on the rename section.

The error message I am receiving is

Rename-Item : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Path'. Specified method is not supported.
At D:\server\MaginusScripts\Powershell\EmailChalgroveReports.ps1:8 char:20

  • ... Item -Path (get-childitem "\zoom-nas\Elucid\System Reporting\Maginu ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidArgument: (:) [Rename-Item], ParameterBindingException
  • FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.RenameItemCommand

Any help appreciated.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 34,191 Reputation points Microsoft Vendor
    2021-03-12T14:10:34.65+00:00

    Hi,

    You have to copy the items, not change the fullnames. And the '-Path' parameter doesn't accept an array.

    $today = Get-Date -Format "MM-dd-yyyy"  
    $source = '\\server\Elucid\System Reporting\Maginus Reports\Chalgrove\Automated Reports\Current\'  
    $destination = '\\zoom-nas\Elucid\System Reporting\Maginus Reports\Chalgrove\Automated Reports\Current\'  
    Get-ChildItem -path $source | ForEach-Object{   
        $newname = $_.BaseName + $today +$_.Extension  
        Copy-Item -Path $_.FullName -Destination (Join-Path $destination $newname)  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments