PowerShell 脚本返回意外输出(随机数)

标签 powershell file-upload httpserver

问题
我正在 PowerShell 中编写一个脚本,将文件上传到 http 服务器。上传成功完成,但它在执行时在控制台中返回一堆数字(远远超过下面显示的数字)。

输出:
enter image description here

这是我正在运行的脚本:

Param([Parameter(Mandatory=$True,Position=1)]
       [string]$user,
  [Parameter(Mandatory=$True,Position=2)]
       [string]$pass,
  [Parameter(Mandatory=$True,Position=3)]
       [string]$dir,
  [Parameter(Mandatory=$True,Position=4)]
       [string]$fileName,
  [Parameter(Mandatory=$True,Position=5)]
       [string]$url 
 )

$filePath = ("$dir" + "$fileName")

$webClient = New-Object System.Net.WebClient;
    $webClient.Credentials = New-Object System.Net.NetworkCredential("$user", "$pass");
    ("*** Uploading {0} file to {1} ***" -f ($filePath, $url) ) | write-host -ForegroundColor Blue -BackgroundColor White
    $webClient.UploadFile($url, "PUT", $filePath);

问题
这些数字来自哪里,我该如何压制它们?

最佳答案

看起来数字是来自 $webClient.UploadFile 的输出.尝试添加 > $null之后,像这样:

$webClient.UploadFile($url, "PUT", $filePath) > $null;

这应该将输出发送到 null,使这些数字不显示。不幸的是,我无法自己测试这种特殊情况。

关于PowerShell 脚本返回意外输出(随机数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37419198/

相关文章:

java - Android Studio上的内部HTTP服务器和Gradle刷新错误

javascript - 识别由 Flex 中的 FileReference 对象为 PNG 图像编码的数据的性质

file-upload - 媒体维基错误 : File upload not working

http - 在 Apache Cassandra 中存储和显示图像文件

java - 如何序列化 HttpHandler 类中的对象

php - 如何在mysql数据库中插入带有文件 uploader 值的多个文本框?

tsql - 无法使用 Transact SQL 脚本中的函数调用执行 powershell 文件

Powershell 脚本在 try/catch block 中捕获的异常时停止; $ErrorActionPreference

windows - 如何在不手动登录从机的情况下以编程方式启动 Jenkins slave

svn - 如何在指定命令的目录名称中使用空格从 PowerShell 调用 CMD.EXE