Powershell copy-item 不会通过 unc 路径复制 txt 文件

Powershell copy-item won't copy txt files over unc path

好吧,所以我很困惑,我到处搜索,但无法弄清楚如何让它工作。

情况:我在工作站 x 上,我需要递归地将 *.txt 从 UNCpath1 复制到 UNCpath2。

如果我这样做:

copy-item -path \source\folders\* -destination \destination\folders$year$month -recurse

一切正常,但我也得到了文件夹。

这些不起作用:

copy-item -path \source\folders\*.txt -destination \destination\folders$year$month -recurse

copy-item -path \source\folders\* -include "*.txt" -destination \destination\folders$year$month -recurse

copy-item -path \source\folders\* -filter "*.txt" -destination \destination\folders$year$month -recurse

我也试过这方面的变体并阅读高低但无法弄清楚。脚本显然不是我的强项。

提前致谢。

您是否尝试过使用 Get-ChildItem 和 foreach 循环? 类似于:

$inputdir = 'UNC Path 1'
$outputdir = 'UNC Path 2'
$filetype = '*.txt'

$files = Get-ChildItem -Path $inputdir -Filter $filetype -Recursive

ForEach ($file in $files)
        { copy-item $file.Fullname -Destination $outputdir }     #using .Fullname to get the full pathname