小编mea*_*ies的帖子

使用PowerShell匹配文件名和副本

我正在努力让这个简单的PowerShell脚本工作.我用谷歌搜索,但我找不到答案.

如您所见,我正在指定源位置和目标位置.

$ filedate变量正在执行dateadd以获取昨天的日期,因为文件名包含日期.

$ filter变量包含我正在搜索的字符串,包括日期部分.

Get-ChildItem命令可以自行运行,但是当我应用过滤器时,它什么都不返回.为了让这个工作,我错过了什么?

$source = "C:\MSSQL.1\Backup\"
$destination = "D:\MSSQL.2\Backup\"
$filedate = (get-date).AddDays(-1).tostring('yyyyMMdd')
$filter = "FULL_(local)_Product_" + $filedate + "*"
Get-ChildItem -Path $source -filter $filter | Copy-Item -Destination $destination
Run Code Online (Sandbox Code Playgroud)

powershell copy file

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

copy ×1

file ×1

powershell ×1