gpt4 book ai didi

powershell - 使用Powershell使用变量将文件从一个位置复制到多个位置

转载 作者:行者123 更新时间:2023-12-03 01:25:59 25 4
gpt4 key购买 nike

因此,我有一个文件,我想使用Powershell从一个位置传输到网络上的多台计算机,这是我到目前为止所拥有的。

robocopy "\\PTFGW-061403573\c$\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" 
"\\$onlineComputers\c$\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" /mir /r:1 /o:0
当我运行它时,它说未找到该位置,并且我可以确认该变量将变量保存在其中。有任何想法吗?

最佳答案

Zizzay,
这是一些应该执行您想要的代码。它将copy-item命令放入TRY / Catch构造中,以捕获并报告复制过程中的任何错误。我假设源代码(启动)上的最后一项是文件夹,因此需要$ CIArgs中的Recurse参数。如果不是文件夹,请删除“递归”行。我也打破了你的道路,减少重复,使事情更容易改变。注意:我在对等局域网上对此进行了测试,应该可以在基于域的局域网上使用。

$onlineComputers = "Computer1","ComputerN"
$FSBase = "C$\ProgramData\Microsoft\Windows\Start Menu\Programs"

$OnlineComputers |
ForEach-Object {

Try {
$CIArgs =
@{Path = "\\PTFGW-061403573\$FSBase"
Destination = "\\$_.\$FSBase\Startup"
Force = $True
Recurse = $True
ErrorAction = 'Stop'}
Copy-Item @CIArgs
}
Catch {
Write-Host @"
Could not write to: $_.
"@
} #End Catch

} #End ForEach...
高温超导

关于powershell - 使用Powershell使用变量将文件从一个位置复制到多个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62877006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com