# Function Return

**URL:** <https://forums.powershell.org/t/function-return/18247>\
**Category:** Open Discussions\
**Created:** [December 28, 2021, 12:16pm UTC](https://forums.powershell.org/t/function-return/18247 "2021-12-28T12:16:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dady](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dady/32/1710_2.png) [@dady](https://forums.powershell.org/u/dady)\
**Post date:** [December 28, 2021, 12:16pm UTC](https://forums.powershell.org/t/function-return/18247/1 "2021-12-28T12:16:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [December 28, 2021, 12:35pm UTC](https://forums.powershell.org/t/function-return/18247/2 "2021-12-28T12:35:25Z")

</div>

Obviously you already used functions …

> [@Having problems with Get-WmiObject in AD](https://forums.powershell.org/t/having-problems-with-get-wmiobject-in-ad/13180):
>
> Hi all, I posted [this](https://powershell.org/forums/topic/function-that-will-determined-if-a-computer-is-laptop-or-desktop/) before and i know that i wrote that everything works fine but i was wrong. I needed it for something in my job and we delayed the project and that’s why i didn’t use it up to now. The whole script eventually doing half the job. Now, it seems that whenever i run the command where the computer name comes from the command "Get-ADComputer " it return an error of RPC on the “Get-WmiObject” but if i put manually the name of the computer it runs good. &nbsp; The functions is: #F…

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.

---

<div class="post-metadata">

**Author:** ![dady](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dady/32/1710_2.png) [@dady](https://forums.powershell.org/u/dady)\
**Post date:** [December 28, 2021, 12:43pm UTC](https://forums.powershell.org/t/function-return/18247/3 "2021-12-28T12:43:32Z")

</div>

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

```auto
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"
    [void]$FileBrowser.ShowDialog()
    #$FileBrowser.FileName
    $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.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [December 28, 2021, 12:49pm UTC](https://forums.powershell.org/t/function-return/18247/4 "2021-12-28T12:49:53Z")

</div>

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

Change this:

```auto
$GFilePath = $FileBrowser.FileName

```

to this:

```auto
$FileBrowser.FileName

```
