Function Return

Hi all,

I can’t get to understand how can i send parameters to a function and receive from it a value i want to use.

For that matter, let say the function gets from the user input of a file path. I need it to return it and to use that file path for other things in my script.
Can someone give me an example?

Thanks in advance

Obviously you already used functions …

What exactly do you have problems with? If you want to (re-)use the output of a cmdlet or function you always can save it to a variable.

Hi Olaf and thanks for your reply.
I’m having problems getting the result of the function and use it.

Function GetFilePath
    Add-Type -AssemblyName System.Windows.Forms
    $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog
    $FileBrowser = InitialDirectory = [Environment]::GetFolderPath('Desktop')
    $FileBrowser.filter = "SpreadSheet (*.csv)| *.csv"
    $GFilePath = $FileBrowser.FileName

I want to call the above function. The function opens a dialog window for the user to choose a file and i need it to return the file path in order for me to use it for other things in the script.

Thanks in advance.

Instead of the variable assignment you simply output the file name …

Change this:

$GFilePath = $FileBrowser.FileName

to this: