【问题标题】:Change the Name of a list of folders更改文件夹列表的名称
【发布时间】:2023-02-20 19:36:55
【问题描述】:

我在 CSV 文件中的 UNC 路径上有一个文件夹列表,条目看起来像这样 \Server\share\sales\John 我想重命名文件夹 John,使其看起来像 Migrated_John,但我需要使用许多不同的路径来执行此操作,并且脚本需要多次使用。所以我不想为每个条目添加一个带有 new_Name 的列,你能帮忙吗

到目前为止我已经写了这个,但我似乎无法正确地做到这一点

$folders = Import-Csv -Path "C:\temp\FolderList.csv"

foreach ($folder in $folders) {
    $oldName = $folder.Path
    $newName = "Migrated_" +
    Rename-Item $oldName $newName
}

+ 之后应该做什么

【问题讨论】:

    标签: powershell rename


    【解决方案1】:

    首先尝试获取 $oldName 的参数:

    $folders = Import-Csv -Path "C:	empFolderList.csv"
    
    foreach ($folder in $folders) {
        $oldName = $folder.Path
        $oldNameParams = Get-Item $oldName
        $newName = "Migrated_" + $oldNameParams.PSChildName
        Rename-Item $oldName $newName
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 1970-01-01
      • 2013-04-04
      • 2012-11-30
      • 2020-06-08
      相关资源
      最近更新 更多