The PowerSHell engine has to "know" the function before you can call it.
Store the function in a .ps1 file.
Then dot-source that .ps1 file. Make sure you are positioned at the directory where the .ps1 is stored, or use the full path
PowerCLI C:\> . ./GetFolderByPath.ps1
Note that there is a blank between the 2 dots !
Now you can call the function
PowerCLI C:\> Get-FolderByPath -Path MYDC/MyFolder | Get-VM | Select Name,....