By default, the hello function will only be available in the script area if you are not using a dot-source script. This means that after the script exits, it is no longer displayed. If you want it to be accessible outside hello.ps1 without a point source, you can declare this function in the global scope:
function global:hello { Write-Host 'Hello, world' }
Then you can simply execute the script and then call the function:
PS C:\temp> .\hello.ps1 PS C:\temp> hello Hello, world
For more information on powershell areas, check out the help .
If you want to just run the code in a function, just don't surround it with a function declaration. In hello.ps1 :
Write-Host 'Hello, world'
Then just name it:
PS C:\temp> .\hello.ps1 Hello, world
source share