小编use*_*127的帖子

Powershell通过网络复制文件

尝试将一些文件从服务器本地复制到网络共享,如下图所示:

文件夹1

在此输入图像描述

文件夹2

在此输入图像描述

我需要实现的是将SOURCE下的ROOT文件夹的所有内容复制到DESTINATION文件夹.但每次复制内容时,我都希望它创建一个具有相同目标文件夹名称但后缀为某种顺序编号的新文件夹.SOURCE/ROOT文件夹中的文件夹和文件数始终保持不变(2个文件夹和2个文件).每次运行脚本时,我只需要将所有这些源内容放入目标的新文件夹中.这是我一直尝试的脚本示例,但它不是我需要的:

$date = Get-Date -format MMMM-dd-yyyy
$date2 = Get-Date -format yyyyMMdd

$Source = "C:\SOURCE\ROOT"

$Destination1 = "\\netshare\DESTINATION\DATA_May-26-2014"
$Destination2 = "\\netshare\DESTINATION\DATA_May-26-2014-1st"
$Destination3 = "\\netshare\DESTINATION\DATA_May-26-2014-2nd"
$Destination4 = "\\netshare\DESTINATION\DATA_May-26-2014-3rd"
$Destination5 = "\\netshare\DESTINATION\DATA_May-26-2014-4th"
$Destination6 = "\\netshare\DESTINATION\DATA_May-26-2014-5th"

#Check destination path
if (Test-Path $Destination1)
 {
  #then copy
  robocopy $Source $Destination2 /MIR /Z /E /fft /MAXAGE:$date2
 }
if (Test-Path $Destination2)
 {
  #then copy
  robocopy $Source $Destination3 /MIR /Z /E /fft /MAXAGE:$date2
 }
if (Test-Path $Destination3)
 {
  #then copy
  robocopy $Source $Destination4 /MIR /Z /E …
Run Code Online (Sandbox Code Playgroud)

powershell copy

10
推荐指数
1
解决办法
7万
查看次数

标签 统计

copy ×1

powershell ×1