PowerShell脚本返回意外的输出

PowerShell脚本返回意外的输出

本文介绍了PowerShell脚本返回意外的输出(随机数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Problem
I am writing a script in PowerShell that uploads a file to an http server. The upload completes successfully, but its returning a bunch of numbers in the console upon execution (far more than what is displayed below).

输出:

这是我正在运行的脚本:

Here's the script I'm running:

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);

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

Question
Where are these numbers coming from, and how do I suppress them?

推荐答案

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

It looks like the numbers are the output coming from $webClient.UploadFile. Try adding > $null after it, like this:

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

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

This should send the output to null, making those numbers not display. Unfortunately I am unable to test this particular situation myself.

这篇关于PowerShell脚本返回意外的输出(随机数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 08:04