Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何在使用阵列的Powershell for循环中使用Robocopy?_Windows_Powershell_Windows Server 2012 R2_Robocopy - Fatal编程技术网

Windows 如何在使用阵列的Powershell for循环中使用Robocopy?

Windows 如何在使用阵列的Powershell for循环中使用Robocopy?,windows,powershell,windows-server-2012-r2,robocopy,Windows,Powershell,Windows Server 2012 R2,Robocopy,我们正在迁移两个共享,比如说oldShare到newShare。我以前从未使用过机器人技术,但从我的谷歌搜索结果来看,这似乎是我应该使用的。文件目录在共享上设置不同,因此我必须使用几个Robocopy命令,而不仅仅是一个。利用我的基本编程知识和在Powershell上的更多搜索,这是我在新共享上运行的脚本: $source_array=@("\\DC02\ArchivedData\IT-Backups", "\\DC02\Contractors", "\\DC02\DataLoad", "\\D

我们正在迁移两个共享,比如说oldShare到newShare。我以前从未使用过机器人技术,但从我的谷歌搜索结果来看,这似乎是我应该使用的。文件目录在共享上设置不同,因此我必须使用几个Robocopy命令,而不仅仅是一个。利用我的基本编程知识和在Powershell上的更多搜索,这是我在新共享上运行的脚本:

$source_array=@("\\DC02\ArchivedData\IT-Backups", "\\DC02\Contractors", "\\DC02\DataLoad", "\\DC02\Infrastructure", "\\DC02\Support")
$destination_array=@("S:\Shares\COMPANYNAME\IT\Archives", "S:\Shares\COMPANYNAME\Public\Contractors", "S:\Shares\COMPANYNAME\Dataload", "S:\Shares\COMPANYNAME\IT\Infrastructure", "S:\Shares\COMPANYNAME\Public\Support")
for ($i=0; $i -lt $source_array.length; $i++) {

    $date=(Get-Date -format dd-MM-yyyy_hh:mm:ss_tt)
    robocopy $source_array[$i] $destination_array[$i] /e /zb /copyall /r:3 /w:3 /xo /log:c:\ROBOCOPY_Logs\$date.log /V /NP

}

这个看起来对吗?我只是想确保我不会把任何事情搞砸,因为我以前从未真正使用过Robocopy或Powershell

有一些语法错误(windows文件名中有冒号之类的),但Powershell部分都很好。谢谢你的信用证建议

我最后的剧本:

$source_array=@('\\DC02\ArchivedData\IT-Backups', '\\DC02\Contractors', '\\DC02\DataLoad', '\\DC02\Infrastructure', '\\DC02\Support')
$destination_array=@('S:\Shares\COMPANYNAME\IT\Archives', 'S:\Shares\COMPANYNAME\Public\Contractors', 'S:\Shares\COMPANYNAME\Dataload', 'S:\Shares\COMPANYNAME\IT\Infrastructure', 'S:\Shares\COMPANYNAME\Public\Support')

for ($i=0; $i -lt $source_array.length; $i++) {

    $date=(Get-Date -format mm-dd-yyyy_hh-mm-ss_tt)
    $filename=('robocopy_iteration' + '_' + $i + '_' + $date)

    # robocopy $source_array[$i] $destination_array[$i] /V /L /TEE /E /COPYALL /ZB /ETA /XO /R:3 /W:3 /LOG:C:\Users\USER\Desktop\$filename.log
    # /L means this is a test, it won't actually copy. Rather it will tell you what will be copied, skipped, etc. 

    robocopy $source_array[$i] $destination_array[$i] /V /TEE /E /COPYALL /ZB /ETA /XO /R:3 /W:3 /LOG:C:\Users\USER\Desktop\$filename.log

}

有一些语法错误(windows文件名中的冒号,诸如此类),但Powershell部分都很好。谢谢你的信用证建议

我最后的剧本:

$source_array=@('\\DC02\ArchivedData\IT-Backups', '\\DC02\Contractors', '\\DC02\DataLoad', '\\DC02\Infrastructure', '\\DC02\Support')
$destination_array=@('S:\Shares\COMPANYNAME\IT\Archives', 'S:\Shares\COMPANYNAME\Public\Contractors', 'S:\Shares\COMPANYNAME\Dataload', 'S:\Shares\COMPANYNAME\IT\Infrastructure', 'S:\Shares\COMPANYNAME\Public\Support')

for ($i=0; $i -lt $source_array.length; $i++) {

    $date=(Get-Date -format mm-dd-yyyy_hh-mm-ss_tt)
    $filename=('robocopy_iteration' + '_' + $i + '_' + $date)

    # robocopy $source_array[$i] $destination_array[$i] /V /L /TEE /E /COPYALL /ZB /ETA /XO /R:3 /W:3 /LOG:C:\Users\USER\Desktop\$filename.log
    # /L means this is a test, it won't actually copy. Rather it will tell you what will be copied, skipped, etc. 

    robocopy $source_array[$i] $destination_array[$i] /V /TEE /E /COPYALL /ZB /ETA /XO /R:3 /W:3 /LOG:C:\Users\USER\Desktop\$filename.log

}

使用
/L
开关和
robocopy
进行测试:
/L::仅列表-不要复制、添加时间戳或删除任何文件。
我会看一下,谢谢!使用
/L
开关和
robocopy
进行测试:
/L::仅列表-不要复制、添加时间戳或删除任何文件。
我会看一下,谢谢!