Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.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 Server 2019上的Robocopy问题_Windows_Powershell_Powershell 4.0_Robocopy_Windows Server 2019 - Fatal编程技术网

Windows Server 2019上的Robocopy问题

Windows Server 2019上的Robocopy问题,windows,powershell,powershell-4.0,robocopy,windows-server-2019,Windows,Powershell,Powershell 4.0,Robocopy,Windows Server 2019,我有一个在WindowsServer2008(Powershell版本4)上运行的robocopy脚本,现在已经有6个月没有问题了 我们最近不得不从这台机器上迁移,以便从Windows Server 2019(Powershell 5)机器上启动相同的脚本。完全相同的脚本不再有效,我不太确定问题出在哪里。剧本是: # Run BCP Bat file to get list of folders that have changed in the past 12 days and save the

我有一个在WindowsServer2008(Powershell版本4)上运行的robocopy脚本,现在已经有6个月没有问题了

我们最近不得不从这台机器上迁移,以便从Windows Server 2019(Powershell 5)机器上启动相同的脚本。完全相同的脚本不再有效,我不太确定问题出在哪里。剧本是:

# Run BCP Bat file to get list of folders that have changed in the past 12 days and save them to 
\\xxxx\xxxx\xxx\xxx\xxx.bat

# Select the starting directory to pull the CSV from.  The assumption is  that  the DB file can #be sent to a dedicated directory that just has only the CSV files 
$Filerecentdir = "\\ZZZ\Z\ZZZ\ZZZZZ\ZZZZ\ZZZZZZ"
#

# Filtering for only CSV files
$Filter = "*.csv"
#

# This PS command will search for the file with  the latest timestamp on it.  Coupling this with #the filter above, we turn $Filerecent into a variable consisting of the most recent CSV
$Filerecent = Get-ChildItem -Path $Filerecentdir -Filter $Filter | Sort-Object LastAccessTime -Descending | Select-Object -First 1
#

# I concatenate $Filerecentdir with the $Filerecent variable to form the full path to the CSV
$FullPath = Join-Path -path $Filerecentdir -ChildPath $Filerecent
#

# $roboSource variable uses import-csv cmdlet to parameterize the one (headerless) column that #the DB file creates
$roboSource = Import-Csv -Header @("a") -Path $FullPath
#

# Arbitrary directory that i'm using to  store the logs.  We'll change this to something on the #file server so it can be viewable
$logPath = "\\AAAA\A\AAAA\AAAA\AAAA\AAAA\"

#creates a folder to seperate weekly logs based off the output of the bat script
$weeklylogfolder = $Filerecent -replace '_.csv'
New-Item -ItemType Directory -Force -Path "$($logPath)$($weeklylogfolder)"
#

# For each loop to iterate over every single row in the CSV
Foreach($script in $roboSource)
{
    # I used the two below variables to replace the two last trailing '\' in each entry
    $prefix = $script.a -replace '\{.+'
    $suffix = $script.a.Substring($prefix.Length) -replace '\\', '_' #keeping the {} in the file #name.
    #$suffix = $script.a.Substring($prefix.Length) -replace '[{}]' -replace '\\', '_'
    #

    #$logFileName = $prefix + $suffix
    $logFileName = $suffix
    #

    # Same switches that we used
    #$StandardSwitches = "/copy:DAT /s /dcopy:DAT /V /L" #no copy
    $StandardSwitches = "/copy:DAT /s /dcopy:DAT /V" #Copy
    #

    # Creates the log file in the same format that we used, so one log file per entry
    $log = "/log:`"$($logPath)$($weeklylogfolder)\$($logFileName).log`""
    #

    # Iterates through each row to create the source and destination
    $FileSource = "$($script.a)"
    $FileDestination = "$($script.a)"
    #

    # used this to surround the certain variables with double quotes, otherwise Robo fails
    $RoboArgs = '"I:\{0}" "Z:\{1}" {2} {3}' -f 
                $FileSource, $FileDestination, $StandardSwitches, $log

    #
    Robocopy $RoboArgs
}
我看不出是什么导致了这个问题。我试着在脚本中单独运行每个命令,当我运行时,我注意到$RoboArgs变量似乎被切断,然后生成一个不完整的$FileDestination

$RoboArgs与上面的一起生成的输出与它在server 2008/Powershell 4上生成的输出完全相同。但是,powershell 5的处理方式似乎有所不同。是否有什么我做错了或需要添加的东西才能正确处理

编辑:

下面是Win2019/Powershell5中$RoboArgs的定义示例:

PS C:\> echo $RoboArgs
"I:\Fake-directory\Fake-directory\D\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}\Fake\FakeDate" "Z:\Fake-Directory\Fake-Directory\D\{DAFD6721-E854-46F3-B
5CF-7EE1861348A6}\Responses\01182020" /copy:DAT /s /dcopy:DAT /V /log:"I:\FakeDirectory\FakeDirectory\Fake\Logs\Folders_Changed_20200118_21.1
\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}_Responses_01182020.log"
它基本上切断第一行的终点,并以相同的方式生成目的地:

PS C:\> Robocopy "I:\Fake-directory\Fake-directory\D\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}\Fake\FakeDate" "Z:\Fake-Directory\Fake-Directory\D\{DAFD6721-E854-46F3-B
5CF-7EE1861348A6}\Responses\01182020" /copy:DAT /s /dcopy:DAT /V /log:"I:\FakeDirectory\FakeDirectory\Fake\Logs\Folders_Changed_20200118_21.1
\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}_Responses_01182020.log"

2020/01/18 23:17:21 ERROR 123 (0x0000007B) Opening Log File I:\FakeDirectory\FakeDirectory\Fake\Logs\Folders_Changed_20200118_21.1

\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}_Responses_01182020.log
The filename, directory name, or volume label syntax is incorrect.


-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : Saturday, January 18, 2020 11:17:21 PM
   Source - I:\FakeDirectory\FakeDirectory\Fake\D\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}\Responses\01182020\
     Dest - Z:\FakeDirectory\FakeDirectory\Fake\D\{DAFD6721-E854-46F3-B
编辑2: 与Win2008/Powershell4相比,如果线路中断,它实际上也会失败。我认为真正的问题在于脚本如何定义源和目标。在2008/Powershell4上,运行脚本可以正确生成所有内容,包括正确的源、目标和日志文件。在2019/Powershell5上运行完全相同的脚本似乎会产生Robocopy如何定义这些路径的问题,将源、目标和日志路径都放在源变量中,即使不是这样定义的:

PS C:\> echo $FileSource
FakeDirectory\FakeDirectory\D\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}\Responses\01182020

PS C:\> echo $FileDestination
FakeDirectory\FakeDirectory\D\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}\Responses\01182020

PS C:\> echo $log
/log:"I:\FakeDirectory\FakeDirectory\FakeDirectory\Logs\Folders_Changed_20200118_21.1\{DAFD6721-E854-46F3-B5CF-7EE1861348A6}_Responses_01182020.log"

PS C:\> echo $StandardSwitches
/copy:DAT /s /dcopy:DAT /V

[1]
$RoboArgs
的哪一部分被切断了?应该是什么&你到底得到了什么?[2] 当服务器2019中没有ps4时,您真的需要它来配合ps4吗?[咧嘴笑]你好,李,我更愿意让它在Win2019/powershell 5上本机安装的设备上运行。我已经编辑了我的问题,以包括powershell似乎是如何处理参数的示例。[1]我不知道为什么目标会被截断,我怀疑您的某个地方有垃圾字符。[2] 日志文件错误非常明显-您有
I:\I:`并且在GUID前面有一个类似于
cr/lf`的东西。我建议您仔细查看srv2019系统将什么放入这些变量中。我认为日志文件实际上是一个错误的复制粘贴作业,实际输出是正确的目录名结构。我确认它存在并且可以访问。我编辑了原始帖子以添加更多细节。我想你的问题可能是这个>>
$RoboArgs=''I:{0}”“Z:{1}{2}{3}'-f
[PowerShell]robocpy-\u Demo\u和\u FullParameterList-Pastebin.com-[1]被切断的是
$RoboArgs
的哪一部分?应该是什么&你到底得到了什么?[2] 当服务器2019中没有ps4时,您真的需要它来配合ps4吗?[咧嘴笑]你好,李,我更愿意让它在Win2019/powershell 5上本机安装的设备上运行。我已经编辑了我的问题,以包括powershell似乎是如何处理参数的示例。[1]我不知道为什么目标会被截断,我怀疑您的某个地方有垃圾字符。[2] 日志文件错误非常明显-您有
I:\I:`并且在GUID前面有一个类似于
cr/lf`的东西。我建议您仔细查看srv2019系统将什么放入这些变量中。我认为日志文件实际上是一个错误的复制粘贴作业,实际输出是正确的目录名结构。我确认它存在并且可以访问。我编辑了原始帖子以添加更多细节。我想你的问题可能是这个>>
$RoboArgs=''I:\{0}''Z:\{1}{2}{3}'-f
[PowerShell]Robocopy\uu-\uDemo\u和\uFullParameterList-Pastebin.com-