Powershell、robocopy阵列:无效参数&;时间戳保持
我有以下Powershell代码:Powershell、robocopy阵列:无效参数&;时间戳保持,powershell,robocopy,Powershell,Robocopy,我有以下Powershell代码: Function CheckFileList() { $limit = (Get-Date).AddDays(-270) $input_path = gci '//network/sourceDir' | sort -property LastWriteTime $output_file = 'c:\PowershellScripts\prune_results.txt' #Clear-Content $output_file
Function CheckFileList()
{
$limit = (Get-Date).AddDays(-270)
$input_path = gci '//network/sourceDir' | sort -property LastWriteTime
$output_file = 'c:\PowershellScripts\prune_results.txt'
#Clear-Content $output_file
$countf = 0
$outputstr = ""
$outputstr = $(Get-Date -format 'F') + " - Folders to be purged:`r`n"
$input_path | Foreach-Object{
if ( (Get-Item $_.FullName) -is [System.IO.DirectoryInfo] ) {
if ( $_.LastWriteTime -le $limit ) {
$source='//network/sourceDir' + $_.Name
$dest="\\computer\c$\targetDir" + $_.Name
$what=@("/MOVE")
$options=@("/COPY:DAT /DCOPY:T")
$cmdArgs = @("$source","$dest",$what,$options)
#"robocopy " + $cmdArgs >> $output_file
robocopy @cmdArgs
$outputstr = $outputstr + " (" + $_.LastWriteTime + ") `t" + $_.Name + "`r`n"
$countf++
$outputstr = $outputstr + "Folders [to be] purged: " + $countf + "`r`n`r`n"
$outputstr >> $output_file
Exit
}
}
}
$outputstr = $outputstr + "Folders [to be] purged: " + $countf + "`r`n`r`n"
$outputstr >> $output_file
}
CheckFilelist
这是为了在保留文件夹时间戳的同时移动多个文件夹(以及其中的文件)
当我运行它时,会出现以下错误:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Mon Apr 27 13:20:35 2015
Source - \\network\sourceDir\someFolder12345\
Dest - \\computer\c$\someFolder12345\
Files :
Options : /COPY:DAT /MOVE /R:1000000 /W:30
------------------------------------------------------------------------------
ERROR : Invalid Parameter #4 : "/COPY:DAT /DCOPY:T"
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.
For more usage information run ROBOCOPY /?
**** /MIR can DELETE files as well as copy them !
我的what/options数组是否有问题?这些参数对我来说是有效的
[编辑]我还发现此脚本未保留文件夹时间戳
someFolder12345
以日期/时间“now”结束在targetDir上。文件夹中的文件保留时间戳,但不保留文件夹?看起来您的字符串“/COPY:DAT/DCOPY:T”
作为一个参数传递给robocopy,而不是作为两个单独的参数。如果选中$options
变量,则该变量在数组中只有一项。尝试将该行更改为$options=@(“/COPY:DAT”,“/DCOPY:T”)
,以便分别传入每个参数。这似乎是有意义的。遇到了一个时间戳没有像现在这样保留的问题running@JohnHubert,我正在尝试将Src文件复制到备份位置,并将Src文件命名为file+TimeStamp。您能告诉我这一行中的错误吗<代码>启动/等待机器人复制%EFM\U TEMP%%EFM\U BACKUP%*。CFX/S/NP/R:5/W:5/XX/MOV/LOG:%EFM\U COPY\U BACKUP%是否需要将/TS
添加为结尾。。?顺便说一下,我是从一个.bat文件运行的