寻找一个PowerShell脚本,可以从一组PC和FTP中提取文件

我正在寻找写一个脚本(最好是powershell),将本质上复制一堆PC的文件,并FTP到服务器。

所以环境的结构就是我们有一个需要放在服务器上的多个PC(大约50个左右)的文件。 有时可能会closures其中一台电脑,因此脚本首先需要确保电脑正常运行(可能是ping结果),然后需要进入该电脑上的目录,从中取出一个文件,重命名文件,放入源目录,然后删除文件。 命名约定并不重要,但date/时间戳将是最简单的。 理想情况下,最好先将所有文件移动到源目录以保存FTP带宽,但由于文件名称相同,文件必须在移动过程中重命名。 移动不复制,因为目录需要为空,所以文件可以在第二天重新创build。 所以一旦移动到源目录,现在所有的文件需要FTP'd到服务器进行处理。

所有这一切,我们需要知道列表中的哪些PC没有响应,所以我们可以手动检索文件,所以脚本应该输出一个文件(txt是好的),将显示哪些电脑的离线。

一切都是一个域,脚本将从具有pipe理员权限的服务器运行。

谢谢!

编辑:

$down = "C:\Script\log\down-hosts.log" $nofile = "C:\Script\log\no-file.log" $computers = Get-Content "C:\Script\list\Computers.txt" $TargetPath = "\\server\directory\directory\" $SourceFileName = "file_name.csv" foreach ($computer in $computers) { if ( Test-Connection -ComputerName $computer -Count 1 -ErrorAction SilentlyContinue { $sourcefilePath = "\\$computer\c$\UPS CSV Exports\$SourceFileName" Write-Host "$computer is up" Write-Host "Copying $SourceFilePath ..." Try { If (Test-Path $SourceFilePath) { Move-Item $SourceFilePath "$TargetPath\$computer`_$SourceFileName" -force } Else { #Throw "$SourceFilePath does not exist" Write-Host "$computer file does not exist" "$computer $SourceFileName file does not exist" | Out-File $nofile -append } } Catch { Write-Host "Error: $($Error[0].Exception.Message)" } } Else { Write-Host "$computer is down" "$computer is down $(get-date)" | Out-File $down -append } } 

一些新的解释:

  • 使用Test-Connection来testing主机是否启动(不能ping)。 – 保持这一点,因为它运作良好

  • 使用New-Item不是必需的。

  • 使用Move-Item而不是FTP协议。

  • 增加了新的日志function: "$computer $SourceFileName file does not exist" | Out-File $nofile -append "$computer $SourceFileName file does not exist" | Out-File $nofile -append提供了显示文件的第二个日志不存在。

  • 增加了新的日志function: "$computer is down $(get-date)" | Out-File $down -append "$computer is down $(get-date)" | Out-File $down -append显示计算机已closures,但也用date/时间标记。