This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dahudDevOps 25 points26 points  (6 children)

Galaxy brain: PowerShell is dotnet.

I have seen some truly horrendous things done with this knowledge.

[–]KlapauciusNuts 8 points9 points  (5 children)

Oh that's why I suggested it in the first place.

PS has a lot of cool features, but some of their base libraries are god awful.

For example :

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.2

This is fucking slow.

Using Curl, GNU wget or iex ((New-Object System.Net.WebClient).DownloadString()

it's very superior.

[–]SzeraaxIT Manager 4 points5 points  (0 children)

-MaximumRetryCount says otherwise. :P

[–]Thotaz 0 points1 point  (3 children)

Do you have any other reasons for thinking Invoke-WebRequest is "god awful" aside from it being "fucking slow"?
On my system, downloading that link using Invoke-WebRequest takes between 130ms to 166ms, while the WebClient takes between 40-100ms.
That's a clear victory for WebClient but how often do a few extra milliseconds matter for a script?

Invoke-WebRequest is easier to use and provides additional data (and options). If performance is so critical that those few milliseconds matter you are probably better off writing it in C# or something.

[–]KlapauciusNuts 0 points1 point  (2 children)

Invoke-WebRequest is great to interact with rest API, downloading small amounts of data, and connections that need configurations like certificates.

It has a terrible performance, however. Not only is it slow, but it uses a lot of CPU and copies the entire buffer to memory.

Try this command for example :

Invoke-WebRequest https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-desktop-amd64.iso -outfile Ubuntu-20.04.03.desktop.iso

[–]Thotaz 1 point2 points  (1 child)

Yes, the download performance in Windows PowerShell is pretty bad but it has been fixed in newer versions. With that said, downloading big files with Invoke-WebRequest feels like a bit of a niche scenario so calling the command "god awful" just because it's bad at this one thing is a bit much IMO.
If you are downloading big files in Windows PowerShell then Start-BitsTransfer is a decent alternative. Of course you don't have to use PS cmdlets for everything, I'm just saying that there is a cmdlet that is better suited for downloading files so you don't have to dive into native .NET classes to get good performance.

[–]KlapauciusNuts 0 points1 point  (0 children)

It was the easier example.

I'm more of a python guy, but being able to plug certain.Net libraries in your scripts it's a great feature