powershell - 带覆盖的复制项目

标签 powershell

在我的一个脚本中,它试图将一个 exe 复制到 C:\Windows\Temp 文件夹。例如:

Copy-Item repo\filename.exe -Destination \\$machine_name\C$\Windows\Temp

错误信息:

Copy-Item : The network path was not found.
At D:\CMPortal\Scripts\ClientRepair\RepairCCMClient.ps1:122 char:33
+                     if(Copy-Item <<<<  cmsetup.exe -Destination \\$install_cmexec\C$\Windows\Temp)
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand

当我手动运行相同的命令时,它起作用了。不知道怎么了。 如果复制的文件存在于目标中,是否有覆盖文件的方法?

提前致谢。

最佳答案

您是否正确使用引号?

Copy-Item 'repo\filename.exe' -Destination "\\$machine_name\C`$\Windows\Temp" -Force

关于powershell - 带覆盖的复制项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15549026/

相关文章:

azure - 在 Docker 容器中运行 Azure PowerShell 脚本

powershell - 使用Powershell将文件重新格式化为管道格式

powershell - 将参数传递给 Start-Job 脚本 block ?

powershell - 通过绝对路径传递变量到命令

powershell - 基于时间的while循环

regex - Powershell获取内容忽略换行符

powershell - 无法在 TFS 后生成脚本中执行 AWS Powershell 工具 cmdlet

powershell - 如何在 powershell 中将多行字符串添加到数组中?

powershell - 我不理解带有开始/处理/结束 block 的函数的参数绑定(bind)

powershell - 无法在 Validateset 中使用预定义数组 - Powershell