cURL not recognizing command line parameters (Windows 10) - windows

Not sure what I'm doing wrong, but any command line parameters I try to pass into curl (using double dash) are interpreted as a url.
Running curl --help:
curl : The remote name could not be resolved: '--help'
At line:1 char:1
+ curl --help
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
With a single dash it seems to interpret a url parameter, but it doesn't find certain parameters. Running curl -sSL:
Invoke-WebRequest : A parameter cannot be found that matches parameter name 'sSL'.
At line:1 char:6
+ curl -sSL
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Curl binary downloaded from https://curl.se/windows/

You can find the answer here: Running curl via powershell - how to construct arguments?
"In PowerShell curl is a built in alias to Invoke-WebRequest cmdlet. And aliases have priority in command resolution. To solve your problem you have more specifically, use curl.exe instead of curl, so command not resolved to alias"

Related

How to use Powershell to download and pipe to execution with arguments

I am trying to use powershell to download and execute a file with arguments:
. { iwr -useb https://github.com/int0x33/nc.exe/blob/master/nc64.exe?raw=true } | iex; <IP> 9001
I get this error:
Unexpected token '9001' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Any help appreciated.
Invoke-Expression (ie) is for interpreting and executing text as PowerShell code[1] - you can't use it to execute a binary download directly (which PowerShell fundamentally doesn't support).
Instead, use Invoke-WebRequest's (iwr's) -OutFile parameter to download the binary content to a local file and execute the latter:
iwr -useb https://github.com/int0x33/nc.exe/blob/master/nc64.exe?raw=true -OutFile ./nc64.exe
./nc64.exe $someIp 9001
[1] The obligatory warning: Invoke-Expression (iex) should generally be avoided and used only as a last resort, due to its inherent security risks. Superior alternatives are usually available. If there truly is no alternative, only ever use it on input you either provided yourself or fully trust - see this answer.

Errors when opening Power Shell or VSC

When I open Windows PowerShell or VSC it prints this message:
Invoke-Expression : At line:1 char:768
... es\Git\cmd;"C:\Users\Shawn\AppData\Local\Microsoft\WindowsApps;C:\Use ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'C:\Users\Shawn\AppData\Local\Microsoft\WindowsApps' in expression or statement.
At C:\Users\Shawn\anaconda3\shell\condabin\Conda.psm1:101 char:9
Invoke-Expression -Command $activateCommand;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
How do I remedy this so that I can be sure that my system will run things correctly.

Unable to connect SonarQube with SQL server

I am using sonarQube and want to connect to sql server db. I ran following command:
sonar-scanner -D sonar.projectKey=MyProject -D sonar.sources=. -D sonar.jdbc.url=jdbc:sqlserver:localhost;databaseName=sonar;integratedSecurity=true
but I am getting below error:-
databaseName=sonar : The term 'databaseName=sonar' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:241
+ ... -D sonar.jdbc.url=jdbc:sqlserver:localhost;databaseName=sonar;integra ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (databaseName=sonar:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Don't put spaces after the 'define' (-D) parameters:
sonar-scanner -Dsonar.projectKey=MyProject -Dsonar.sources=. -Dsonar.jdbc.url=jdbc:sqlserver:localhost;databaseName=sonar;integratedSecurity=true

About MicrosoftTeams-TeamFunSettings

Today I found that the MicrosoftTeams powershell command Get-TeamFunSettings failed to run when the property GiphyContentRating value is "Allow all content".
Error info:
Get-TeamFunSettings : Error converting value "unknownFutureValue" to
type
'System.Nullable`1[Microsoft.TeamsCmdlets.PowerShell.Custom.Model.GiphyRatingType]'.
Path 'funSettings.giphyContentRating', line 1, position 844. At line:1
char:1
+ Get-TeamFunSettings -GroupId a3f33284-82a5-4643-a43d-401f2568177c
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-TeamFunSettings], JsonSerializationException
+ FullyQualifiedErrorId : Newtonsoft.Json.JsonSerializationException,Microsoft.TeamsCmdlets.PowerShell.Custom.GetF
unSettings
We are actively investigating this issue and a fix is expected shortly. Note this commend is in beta so instability is not unexpected.
Maybe it's just very new but according to the documentation of the command "Allow all content" is not an option. (I do think it should be one, though)
https://learn.microsoft.com/en-us/powershell/module/teams/set-teamfunsettings

Unable to curl from Windows 10 Powershell with X-API-KEY

I have been trying to curl from windows powershell but no luck.
curl -O -J -H #{'X-Api-Key' = 'abcdefghijk'} https://my.repo.com/abc/xyz
I am getting the following error
curl : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ curl -O -J -H #{'X-Api-Key' = 'abcdefgh'} ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
As #Robin pointed out in his comment; curl is an alias for Invoke-WebRequest (see your exception details for more information!
So basically... it's not curl!
This means that the switches you are providing might not map as you'd expect.
First thing to mention is that whilst PowerShell allows you to use shortened parameter names, you really, really shouldn't use them!
-O = -OutFile (probably not what you want...)
-J = ...there is none!
-H = -Headers (looks right for you)
I reckon that's the root cause of your issues - you need to look at the documentation for the CmdLet
Get-Help Invoke-WebRequest
Get-Help Invoke-WebRequest -Online ## this will open in browser with full details

Resources