PowerShell Script Returning Unexpected Output (random numbers)

天涯浪子 提交于 2021-01-27 06:46:04

问题


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

Output:

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?


回答1:


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;

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



来源:https://stackoverflow.com/questions/37419198/powershell-script-returning-unexpected-output-random-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!