How to call a function in another file ?

# file library.ps1

Function enviar {

param($para)

Write-Host $para

}

# file command.ps1

enviar "Hello"
# file library.ps1

Function enviar {

param($para)

Write-Host $para

}

# file command.ps1
. .\library.ps1
enviar "Hello"

A “library” is a basically a Powershell module.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_modules?view=powershell-7
https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-script-module?view=powershell-7

Another option is dot sourcing, like this

# file enviar.ps1

Function enviar {

param($para)

Write-Host $para

}

# file command.ps1

.\enviar.ps1 "Hello"

If it’s something that you use all of the time, you can also use a Powershell profile to keep common functions available when the Powershell session loads on you’re main computer.

https://www.sconstantinou.com/powershell-profiles/

Are you sure that would work this way? I’d expect this way you provide the parameter to the script and not to the contained function.

@Olaf, I’m not sure I even be talking to you, I see above your thread has been reported :wink:

You are correct, it would be more like this:

# file enviar.ps1

param($para)

Write-Host $para


# file command.ps1

.\enviar.ps1 "Hello"

I typically would still lean towards a Module, but you could load a script into memory to load functions.