-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Piping off Invoke-RestMethod not expanding as expected #15272
Comments
This is probably due to how the API returns the result, it can depend on the endpoint, but it is noticeably different at times to how Windows PowerShell handled it, I think. There's been a lot of discussion over it, and at the moment I don't recall if there was ever an agreement to change the behaviour or not. The quick workaround is just to pipe the result through |
That's interesting. I imagine any change to the behavior would probably be a breaking change, so if it's something already at least somewhat known it's certainly easy enough for me to work around. Was just the first time I had ever encountered it and my 15 minutes of Google didn't return me anything that seemed to match documentation wise. |
Yes, when
It would make sense to me to change A simpler alternative to the (Using |
Order of operations type deal I got it. From a user perspective I can say the behavior I expected was enumeration like most every other command you send down the pipeline, but if the trade-off of changing the functionally does more harm then good then it may not be worth it in the grand scheme of things. (I don't know the consensus on why ConvertFrom-JSON was changed and if this checks similar boxes) It would definitely make sense to me however to add a footnote on this objectively, nonstandard behavior to the Microsoft docs page for the cmdlet since I feel that's where most users, like myself, would turn to for guidance. |
Good idea, please see MicrosoftDocs/PowerShell-Docs#7504
To me, definitely - if the change was worth it for |
If it is true behavior please open new clear issue with the request. |
PowerShell doesn't enumerate objects in an array before routing through the pipeline. This creates the issue where the properties that are selected are not seen as the enitire array is passed. To correct this I added encapsulation which forces enumeration. Reference: PowerShell/PowerShell#15272 #issuecomment-822620722 Shorten URL: https://rb.gy/67s9d
Steps to reproduce
This may not be an issue at all and just something in Powershell I am unaware of. While making a call to an internal REST API I noticed a difference when piping to a ForEach-Object vs saving the output to a variable first and running in a ForEach loop. If I do not either expand a property on the call or save it to a variable first then the output gets piped over to the foreach a single time as the full array. Does it have to serialize the data first or something? I've tried finding any relevant documentation for this exact scenario but haven't had any luck so far.
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: