我有一个脚本(粘贴以下)这是应该做到以下几点:匹配定义的模式是 PowerShell的布展项目 - 不移动文件
- 循环并抓住所有文件位置
- 原始的源文件移动到另一个位置(如果复制成功)
它做的步骤#1和#2,但步骤#3,布展项目是不动的任何文件,我不知道为什么,我没有得到ind错误代码
有人可以帮忙吗?谢谢
$source = "C:\Users\Tom\"
$source_move = "C:\Users\Tom\OldLogBackup1\"
$destination ="C:\Users\Tom\Mirror\"
if(-not(Test-Path $destination)){mkdir $destination | out-null}
ForEach ($sourcefile In $(Get-ChildItem $source | Where-Object { $_.Name -match "Daily_Reviews\[\d\d\d\d-\d\d\d\d\].journal" }))
{
#escape filename because there are brackets in the name!
$src = [Management.Automation.WildcardPattern]::Escape($sourcefile)
Copy-Item $src $destination
### Check for a successful file copy
if($?)
{
####
if(-not(Test-Path $source_move)){
echo "Path does not exist!"
} else {
echo "Path exists!"
### Move original source file someplace else
Move-Item $source_move$sourcefile $source_move
if($?)
{
echo "Source file successfully moved"
} else {
echo "Source file was not successfully moved"
}
}
}