0

I run the below cUrl command to get an X-SDS-AUTH-TOKEN. Is there any way I can convert this to Powershell to be able to script it? I'm been playing around with it, but not having much success. Any help greatly appreciated.

curl -L -v -k https://172.31.110.16:4443/login -u username:password

Thanks

I've looked at a lot of articles online, but nothing seems to point in the right direction.

1 Answers1

0

Disclaimer - ive no idea what X-SDS-AUTH-TOKEN is - but you appear to be performing a simple GET request with BASIC auth so...

Step 1 - understand the command you want to replicate - consult the man page for Curl and read about each of the arguments your passing to curl -L -v -k and -u username:password. In summary:

  1. -L - this instructs Curl to follow redirects
  2. -v - enable Curl's verbose output
  3. -k - allows "insecure" SSL connections (self signed / expired / untrusted certificates)
  4. -u user:pwd - pass username "user" and password "pwd" to the webpage

Step 2 - Powershell gives you a few options, but for a simple GET request take a look at Invoke-WebRequest.

Comparing the default behavior of Invoke-WebRequest to curl you will find:

  1. Invoke-WebRequest follows redirects by default
  2. PowerShell provides a -Verbose switch with many commands, but this is not required
  3. Invoke-WebRequest provides -SkipCertificateCheck in newer versions of powershell, but it can be achieved via .Net for older versions. This is a security risk - make sure you understand the implications of bypassing certificate checks.
  4. I think curl will do BASIC auth by default. Invoke-WebRequest has an -Authentication switch (but it requires a powershell credential object) - BUT you might find it easier to create an Authorization header yourself using the -Headers switch.

I'm not going to give you a full solution, but this should point you in the general direction. Good luck!

MisterSmith
  • 2,884
  • 1
  • 10
  • 13