【发布时间】:2014-11-18 07:21:07
【问题描述】:
以下是我的 powershell 脚本中的确切场景。
$Source = "C:\MyTestWebsite\"
$Destination = "C:\inetpub\wwwroot\DemoSite"
$ExcludeItems = @(".config", ".csproj")
Copy-Item "$Source\*" -Destination "$Destination" -Exclude $ExcludeItems -Recurse -Force
如果目标文件夹中不存在 .config 和 .csproj 文件,我希望此代码复制它们。当前脚本只是将它们排除在外,无论它们是否存在。 目标是,我不希望脚本覆盖 .config 和 .csproj 文件,但如果它们在目标位置不存在,它应该复制它们。
知道脚本中需要进行哪些更正吗?
对此的任何帮助将不胜感激。
谢谢
【问题讨论】:
-
某种使用 Test-Path 的 If 语句似乎是有序的。
-
这听起来像是 Robocopy 的工作,而不是 PowerShell 脚本。
标签: powershell powershell-2.0 powershell-remoting copy-item