I need to upload a file to a web server (to a Jira server, actually). The below code works perfectly when the script is run in PowerShell ISE:
$WebClient = new-object System.Net.WebClient
$WebClient.Headers.Add("Authorization", "Basic " + $AuthStr)
$WebClient.Headers.Add("X-Atlassian-Token", "nocheck")
$WebClient.UploadFile($BasePath + "/attachments", $AttachmentFile) >$null
However, the same code with the same data throws an error when executed in a usual PowerShell console window:
Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At C:\Temp\Qualys\ProcessWeeklyReport.ps1:69 char:5
+ $WebClient.UploadFile($BasePath + "/attachments", $AttachmentFile ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
I was unable to obtain a more detailed error message. No PowerShell profiles have been created, the Powershell environment is in its default state.
Replacing the plain string with [system.uri] type variable doesn't change the situation.
This is a local issue, not an error returned by the web server. Packet sniffer doesn't show any communications to the server if the error is thrown.
Can someone suggest where to dig?