2

I have a Linux box running Ubuntu Server 16.04 with Powershell on it, from the Linux terminal if I run:

sudo powershell (Invoke-Webrequest http://ipinfo.io/json | ConvertFrom-Json).ip 

I get an error saying it is formatted incorrectly and expected a ')' at the end. if I remove the () and just try to convert from JSON it throws a could not find the command ConvertFrom-Json.

That said if I actually go into powershell and run the original command it works perfectly.

Any help would be greatly appreciated.

2 Answers 2

3

I figured it out need to wrap the command like this

sudo powershell '(Invoke-Webrequest http://ipinfo.io/json | ConvertFrom-Json).ip'

thank you for your help!

Sign up to request clarification or add additional context in comments.

Comments

2

I haven't used PowerShell on Linux (yet), but on Windows you'd need

powershell -Command { (Invoke-WebRequest http://ipinfo.io/json | ConvertFrom-JSON).ip }

2 Comments

Thanks Jeff I just tried and I still get the -Bash syntax error near unexpected token '('
OK, I don't speak bash, but my next suggestion would involve doing whatever bash requires to escape the parens - perhaps \( and \)? You may also need to escape the | as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.