我对Powershell还是很陌生,想知道是否有人可以指出正确的方向。
我一直在寻找一个脚本,可以帮助我实现以下目标:
最佳答案
有遵循您的逻辑的powershell脚本。目标可以是UNC路径。
$source = "C:\Tmp\Test.txt"
$destination = "C:\Tmp\Destination\Test.txt"
$TestPath = Test-Path $destination
IF (!$TestPath)
{Copy-Item $source $destination -Verbose
PC1 - no file found. Copying}
ELSE
{
IF (((Get-ChildItem $source).Length -ne (Get-ChildItem $destination).Length) -or ((Get-ChildItem $source).LastWriteTime -ne (Get-ChildItem $destination).LastWriteTime))
{Copy-Item $source $destination -Force -Verbose}
ELSE
{"PC2 - exact file found, nothing copied"}
}
关于powershell - 检查文件在远程计算机上是否存在。如果没有,请复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140820/