首页 > 解决方案 > Powershell复制具有特定数字的多个文件

问题描述

对 Powershell 来说仍然很新,我想将多个文件从一台服务器复制到另一台服务器。我要复制的文件包含相同的两个数字 18 或 19。

Copy-Item -Path \\test\files\07_Export -Filter '*18.csv' -Destination \\test01\files$\2018;

Copy-Item -Path \\test\files\07_Export -Filter '*19.csv' -Destination \\test01\files$\2019;

例如 Test18.csv

问题19.csv

搜索18.csv

现在它只是复制空文件夹 07_export。

标签: powershellfilterserver

解决方案


这应该符合您的目的。

$filename = (Get-ChildItem "<Source Folder>" -Recurse | Where-Object { $_.FullName -imatch "18" -or $_.FullName -imatch "19" }).FullName
foreach ($file in $filename) {
    Copy-Item -Path $file -Destination "<Destination Folder>"
    }

推荐阅读