0

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?

Badro Niaimi
  • 1,027
  • 1
  • 12
  • 23
  • 1
    Are just you trying to call that function? – zdan Nov 25 '19 at 16:57
  • I need to enter a URL and a filename. The URL is the source of a file. The filename is the destination output of the downloaded URL file. – DouglasMoody Nov 25 '19 at 17:00
  • I recognize this now. The $URL and $Filename must be specified before the function begins. I will set this information first. May be a confusing question because it is entry level Powershell. And yes @zdan , the function is called if a situation exists. – DouglasMoody Nov 25 '19 at 17:05

1 Answers1

2

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.

logicaldiagram
  • 814
  • 11
  • 17