0

I am sending a query with Invoke-WebRequest and want to output a value from the response header. For this I wrote a function that contains the following query:

Invoke-RestMethod @Params -ResponseHeadersVariable ResponseHeader

The Result as expected:

$ResponseHeader.'OData-EntityId'

xxxx-xxxx-xxxx-xxxxxxx

However, if I put this logic into a function, I get an additional blank line that interferes with further processing of the value. How do I get rid of it?

enter image description here

Gill-Bates
  • 559
  • 8
  • 22

1 Answers1

0

I have solved it with adding | Out-Null

Invoke-RestMethod @Params -ResponseHeadersVariable ResponseHeader | Out-Null

Gill-Bates
  • 559
  • 8
  • 22
  • 1
    Just as a side note, `$null = Invoke-RestMethod` or `[void](Invoke-RestMethod)` are both more efficient as they do not pass the result through the pipeline to another cmdlet. Using `Out-Null` a lot will slow your functions or script down. Worth noting if performance is a consideration. – Ash Apr 27 '23 at 12:27