问题
我正在 PowerShell 中编写一个脚本,将文件上传到 http 服务器。上传成功完成,但它在执行时在控制台中返回一堆数字(远远超过下面显示的数字)。
输出:
这是我正在运行的脚本:
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/