DouglasMoody
DouglasMoody

Reputation: 28

How to fill in URL & Filename parameters in this specific example

I need to simply specify the $URL & $Filename (source destination basically) but do not know the syntax and assume this is where I would enter it:

function Get-FileFromURL {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)]
        [System.Uri]$URL,
        [Parameter(Mandatory, Position = 1)]
        [string]$Filename
    )

Reference Source of above code:

Downloading large files in Windows command prompt / PowerShell

*Kobalt's comment.

Do I need to simply set $URL & $Filename prior to the function?

Upvotes: 0

Views: 743

Answers (1)

logicaldiagram
logicaldiagram

Reputation: 1114

There are a couple of ways to call a function (with a formal param block) in PowerShell and provide parameter values.

Positional (space-delimited and parameters are matched based on Position):

Get-FileFromURL http://someurlstring somepathstring

Named (order doesn't matter, the parameter name is the variable name in the param definition):

Get-FileFromURL -URL http://someurlstring -Filename somepathstring

Either of these will invoke the Get-FileFromURL with the values you provide.

The URL parameter is expecting a Uri object type, but PowerShell/.Net will convert a string for you as long as it meets the URI format.

Upvotes: 2

Related Questions