George
George

Reputation: 59

PowerShell: How to prevent truncated string output?

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

Upvotes: 2

Views: 4487

Answers (2)

Drew
Drew

Reputation: 4020

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

Upvotes: 4

phuclv
phuclv

Reputation: 41784

Print the property directly

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

Upvotes: 2

Related Questions