I've got a PowerShell function Download-File
, which uses WebClient.DownloadFile
-- hence the name.
When I attempt to turn my .ps1
script into a .psm1
module, PowerShell warns me that "Download" is not in the list of recommended verbs.
What's a good alternative? Get-
seems to be about getting properties, rather than contents (apart from Get-Content
, oddly). Receive-
seems a bit too passive for my liking (i.e. the script blocks until the information is sent) -- which doesn't fit well.
Ideas?
PowerShell verbs are assigned to a group based on their most common use. The groups are designed to make the verbs easy to find and compare, not to restrict their use. You can use any approved verb for any type of command. Each PowerShell verb is assigned to one of the following groups.
You may get a complete list of verbs using the Get-Verb cmdlet.
A cmdlet is a lightweight command that is used in the PowerShell environment. The PowerShell runtime invokes these cmdlets within the context of automation scripts that are provided at the command line. The PowerShell runtime also invokes them programmatically through PowerShell APIs.
Get-Command gets the commands from PowerShell modules and commands that were imported from other sessions. To get only commands that have been imported into the current session, use the ListImported parameter. Without parameters, Get-Command gets all of the cmdlets, functions, and aliases installed on the computer.
A file can be downloaded with Microsoft PowerShell via the Invoke-WebRequest command. The PowerShell offers three aliases of Invoke-WebRequest i.e., iwr, curl, and wget. This post demonstrates various methods to download a file using PowerShell.
A faster and better way is to use the Start-BitsTransfer cmdlet in PowerShell. This cmdlet allows you to queue files, set priority (useful for bandwidth limitation), can run in the background and download multiple files asynchronous.
Windows PowerShell 5.1 or PowerShell 7.1 (recommended). Windows 10 already includes Windows PowerShell 5.1. A web site that hosts the files to download. For non-authenticated file downloads, consider using the Tele2 Speedtest site, which is free.
Perhaps the most used cmdlet in this article, Invoke-WebRequest, can download HTTP, HTTPS, and FTP links. Whether the source location requires users to log in, the Invoke-WebRequest cmdlet can handle requests with credentials as well.
For me, 'Get' is the most natural verb. It gets everthing, not just properties. For the noun I would use something like 'WebFile', you can easily guess what you get and where it is coming from.
Wouldn't this work:
Start-Download -Url http://blah/
Or use Invoke-Download
, as per the recommendations for synchronous operations. Start
is for asynchronous.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With