I just ran your post code sample on OSX, in VSCode editor, both terminals, and via the normal default PSCore terminal and it ran as expected.
Also, remember the proper naming construct in PowerShell if verb-noun. So your function should be something line New-ttr.
#!/usr/bin/env pwsh
function New-ttr{
Param(
$file,
$name
)
write-host $file
write-host $name
}
So, I saved the code as test.ps1 in my downloads folder and executed with …
~/downloads/test.ps1
... from each of the terminals. Running in the VSCode editor is just a matter of selecting the text...
function New-ttr{
Param(
$file,
$name
)
$file
$name
}
New-ttr -$file Somefilename -name somename
select terminal and run selected text or run Active File. Lastly, don't use Write-Host unless you are coloring screen text output, or other needed formatting conditions. Output to the screen is the default.
So, this...
write-host $file
write-host $name
.. and this...
$file
$name
… will do the same thing.
Write-Host is not pipeline friendly, and clears the buffer, so it's use is strongly discouraged.
If you want to use a write for screen output, consider using Write-Output or one of the other Write-* cmdlets.
Though I am unsure why you are passing both params $file and $name, even in this test. My assumption is one is a path and the other is the name of the file to look for. You can just pass the fullpath of the file in $file and extract the name using $file.Name.
about_Functionsdocumentation?