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.

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.

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.