2

I am trying to run curl command in powershell console

curl.exe -v -U x7878:asdff$ -H "Content-Type: application/json" -X POST --data @login.txt https://mywebsite/ma/api/v2/user/login

anyidea where do i miss?

the error i got is:

The splatting operator '@' cannot be used to reference variables in an expression. '@login' can be used only as an argument to a command

I have been also trying to put into variables like

PS>$a="My above command"
PS>$b=invoke-expression $a

It does not work either, it is making worse due to "(double quotes) sign.

Vivek Kumar Singh
  • 3,223
  • 1
  • 14
  • 27
Yesaya
  • 21
  • 3

1 Answers1

1

As for what you are doing in your post with curl.exe in the shell. See this answers. Thus your post falls into the possible duplicate answer based on the below and more like them on this site.

Running curl via powershell - how to construct arguments?

Powershell curl double quotes

Since this appears just to be a text file, then you just need the text file name without any special characters involved.

There are many reserved characters, and you just cannot randomly use them. The '@' is one of those.

@( ) Declare arrays.

@{ } splatting use case, Declare hash tables..

@' ... '@ Use Multi-line string literal without embedded variables.

$ (dollar sign) Declare/use a variable and there are a boatload of built-in variables. Just use the consolehost/ISE/VSCode and type $ and press the tab key to scroll through them or see:

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables

If you need to use special characters, you have to escape them

As far as Invoke-Command is concerned, be sure to look at the help file for the proper understanding and use via the examples provided in the help files.

Get-Help -Name Invoke-Command

NAME
    Invoke-Command

SYNOPSIS
    Runs commands on local and remote computers.

vs

Get-Help -Name Invoke-Expression

NAME
    Invoke-Expression

SYNOPSIS
    Runs commands or expressions on the local computer.
postanote
  • 15,138
  • 2
  • 14
  • 25
  • 1
    Thank you for pointing out this. By enclosing '@login' on the command, it works nicely and i can run invoke-expression correctly. – Yesaya Jul 19 '18 at 04:23