Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
运行带有gsutil cp到GCP的powershell脚本可以在多行上显示上载进度_Powershell_Gsutil - Fatal编程技术网

运行带有gsutil cp到GCP的powershell脚本可以在多行上显示上载进度

运行带有gsutil cp到GCP的powershell脚本可以在多行上显示上载进度,powershell,gsutil,Powershell,Gsutil,我有一个简单的powershell脚本,它从Win'2008R2系统上的任务调度器运行,该系统基本上只运行以下命令: gsutil-o gsutil:parallel\u composite\u upload\u component\u size=0 cp-L C:\logs\log1.txt C:\archive\*.zip gs://temp 我正在使用Start Transcript将输出记录到results.log文件中。问题是,当它将zip文件上载到gcp时,它会在上载过程中每隔64K

我有一个简单的powershell脚本,它从Win'2008R2系统上的任务调度器运行,该系统基本上只运行以下命令:

gsutil-o gsutil:parallel\u composite\u upload\u component\u size=0 cp-L C:\logs\log1.txt C:\archive\*.zip gs://temp

我正在使用Start Transcript将输出记录到results.log文件中。问题是,当它将zip文件上载到gcp时,它会在上载过程中每隔64KB记录多行的进度:

Resuming upload for file://E:\db\db1.zip
Uploading   gs://temp/db1.zip:             0 B/1.20 GiB
Uploading   gs://temp/db1.zip:             98.75 MiB/1.20
Uploading   gs://temp/db1.zip:             98.81 MiB/1.20
...and keeps repeating this until it uploads the entire 1.20 GB.
因为results.log文件将通过电子邮件发送给一群人,所以我不需要他们看到所有这些垃圾。只显示其中一行和最终文件大小就足够了

当我从windows命令提示符(或从本机powershell)运行命令或脚本时,使用:powershell.exe-文件c:\scripts\upload.ps1,它将按预期工作,并在一行上显示进度:

Resuming upload for file://E:\db\db1.zip
Uploading   gs://temp/db1.zip:             1.20 GiB/1.20 GiB
以前,当我在没有'-o GSUtil:parallel_composite_upload_component_size=0'参数的情况下运行同一个命令时,它向我显示了相同的长输出,但一旦我将其添加到GSUtil中,我认为这很好,因为它不再在PS命令提示符中的一堆行上重复该过程。因此,只有当我从任务调度器运行脚本时,才会发生这种情况


你知道为什么会发生这种情况吗?我该如何解决这个问题?

当输出指向非交互式终端时,可以禁用进度微调器。

你收到的输出是正确的。在“progress”的命令提示符中,您看到的是多条消息,只是它们在同一行上被一次又一次地覆盖,这使得它“看起来”像是一个单行条目,而在实际情况中,它是多个输出语句(如在您的成绩单文件中捕获的)。唯一的解决办法是,如果程序中有一个开关,不输出进度,而只是完成传输。看看这个。显然,-L开关是这样的,程序可以从它停止的地方开始。因此,不会有一个开关,使它成为一个单一的文件上传行。不过,应该可以编写一个脚本来过滤日志文件。它是否曾经更改为上传或完成,类似这样的内容?我目前正在尝试将其过滤成$file字符串…到目前为止,我有类似的内容:$file=@(获取内容-路径$Log)。其中({$\.Trim()-notin$pattern1+$pattern2})-但不确定如何仅保留上载进度的第一行和最后一行。所以我想我需要做一些类似于:$pattern1=@('Uploading*')的模式,我已经尝试过了,但它只有在与日志中的行完全匹配时才能找到该行。通配符不起作用。@Patrick Mcvay:不起作用。谢谢,我以前没见过。现在,我必须过滤掉字符串中包含“Uploading gs:*的所有行。