Powershell 检查远程计算机上是否存在文件。如果没有,请复制它
我对powershell非常陌生,不知道是否有人能为我指明正确的方向 我想写一个脚本来帮助我完成以下工作:Powershell 检查远程计算机上是否存在文件。如果没有,请复制它,powershell,powershell-2.0,Powershell,Powershell 2.0,我对powershell非常陌生,不知道是否有人能为我指明正确的方向 我想写一个脚本来帮助我完成以下工作: 我有一个文件需要推送到远程机器 我有一个远程计算机名列表,我想检查一下文件是否存在 如果文件存在且大小和日期相同,则不执行任何操作 如果文件不存在,或者日期/大小不同,则复制该文件 我可能还想写入某种日志/文本文件以指示状态,例如“PC1-未找到文件。正在复制”或“PC2-已找到确切的文件,未复制任何内容” 你考虑过使用机器人镜头吗?如果您是本地计算机的管理员,则可以将其复制到本地计算机
你考虑过使用机器人镜头吗?如果您是本地计算机的管理员,则可以将其复制到本地计算机 \pcname\c$\path\
如果需要,您可以执行差异复制和镜像。有一个符合您逻辑的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"}
}