I am trying to access a URL with a character /in it from powershell using the following command (this is a request to the gitlab server to get a project called "foo/bar"):
Invoke-WebRequest https://server.com/api/v3/projects/foo%2Fbar -Verbose
Now it’s strange that using PowerShell ISE or Visual Studio, the request is fine. When using PowerShell itself, the URL is not automatically activated, and the request fails. For instance.
In ISE / VS:
$> Invoke-WebRequest https://server.com/api/v3/projects/foo%2Fbar -Verbose
VERBOSE: GET https://server.com/api/v3/projects/foo%2Fbar with 0-byte payload
VERBOSE: received 19903-byte response of content type application/json
StatusCode : 200
StatusDescription : OK
Content : .... data ....
In Powershell:
$> Invoke-WebRequest https:
VERBOSE: GET https:
Invoke-WebRequest : {"error":"404 Not Found"}
At line:1 char:1
+ Invoke-WebRequest 'https://server.com/api/v3/projects/foo%2Fbar ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I tried adding single and double quotes around the url but nothing helps.
What could be causing this behavior, and how to make PS not delete the URL string?
Environment: Windows 7, also tested on a 2012R2 server with the same results.
$> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2