2

I am trying to do a simple invoke rest method request for my API Authentication, however the bearer token is displaying a truncated output. How do I display the output string entirely?

PS C:\WINDOWS\system32> Invoke-RestMethod -Method POST -Body $body -uri $uri

access_token
------------
gAAAAMAEzhS8pzLrV5I1d5CJuyLq0BbBHaBAFhLzs9Uqk3zUueEvyxJ3NQN5KrTpexrFi7aUYbgvDzA0nQf7caGddeIngxC0uGjpVBlT5AlHbddwDiQhb4Ruh2BQry9dhmzN47Mz840FAU8WOrtQNXEundiaaN30nqel2365TEZc1uU15AIAAIAAAAAc_fYAsOVgvBOlg7QKGxgMbewrxaav-eprjqci9mCFQtfke...

I have tried addting the Out-String on the end but it shows me this error:

Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'Out-String'.
At line:1 char:1
+ Invoke-RestMethod -Method POST -Body $body -uri $uri Out-String -Widt ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

2 Answers 2

4

You can add | Select-Object -ExpandProperty access_token to show the entire string value.

Using Select-Object -ExpandProperty will enumerate the value of the property that you pipe to it and output the value as a single record.

So instead of getting

access_token
------------
abcdefg1234....

you get

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

Comments

2

Print the property directly

(Invoke-RestMethod -Method POST -Body $body -uri $uri).access_token

Comments

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.