• SOLUTION 1.
If you need to use a function that is in another script file, you can import that function with the Import-Module cmdlet
Functions.ps1 Contains the full functions. This script needs to be imported by the main script.
function Write-TextColor
{
Param(
[parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[Object]
$Info,
[parameter(Position=1, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[System.ConsoleColor]
$ForegroundColor = [System.ConsoleColor]::White,
[parameter(Position=2, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[Switch]
$NoNewLine
)
Process{
foreach ($value in $Info)
{
if($NoNewLine)
{
Write-Host $value -ForegroundColor $ForegroundColor -NoNewline
}
else {
Write-Host $value -ForegroundColor $ForegroundColor
}
}
}
}
function Write-InfoBlue
{
Param(
[parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[Object]
$Information,
[parameter(Position=1, ValueFromPipeline=$true)]
[Switch]
$NoNewLine
)
Process{
Write-TextColor $Information Blue $NoNewLine
}
}
Main.ps1
Import-Module -Name "$($PSCommandPath | Split-Path)/Functions.ps1" -Force
Write-InfoBlue "Printed from imported function."
Console Output

• SOLUTION 2.
Functions.ps1 Contains the full functions. This script needs to be imported by the main script. Same as Solution1's Script.
Main.ps1
This script contains 3 functions.
1. Get-ScriptFunctionNames. It returns an array of String, each element is the name of function.
2. Get-ScriptFunctionDefinitions. It returns an array of String, each element is the complete function.
3. Get-AmalgamatedScriptFunctionDefinitions. It returns only one String, the result of joinning all elements returned by the function Get-ScriptFunctionDefinitions.
All 3 need the same param, the path of the Powershell script file.
We will test the 3 functions on this file.
This script doesn't use Import-Module cmdlet.
function Get-ScriptFunctionNames {
param (
[parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[AllowEmptyString()]
[AllowNull()]
[System.String]
$Path
)
Process{
[System.Collections.Generic.List[String]]$FX_NAMES = New-Object System.Collections.Generic.List[String]
if(!([System.String]::IsNullOrWhiteSpace($Path)))
{
Select-String -Path "$Path" -Pattern "function" |
ForEach-Object {
[System.Text.RegularExpressions.Regex] $regexp = New-Object Regex("(function)( +)([\w-]+)")
[System.Text.RegularExpressions.Match] $match = $regexp.Match("$_")
if($match.Success)
{
$FX_NAMES.Add("$($match.Groups[3])")
}
}
}
return ,$FX_NAMES.ToArray()
}
}
function Get-ScriptFunctionDefinitions {
param (
[parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[AllowEmptyString()]
[AllowNull()]
[System.String]
$Path
)
Process{
[System.Collections.Generic.List[String]]$FX_DEFS = New-Object System.Collections.Generic.List[String]
if(!([System.String]::IsNullOrWhiteSpace($Path)))
{
Import-Module -Name "$Path" -Force
}
$names = Get-ScriptFunctionNames -Path $Path
Get-ChildItem "function:" | Where-Object { $_ -in $names } | ForEach-Object{
$FX_DEFS.Add("function $($_.Name) { $($_.Definition) };")
}
return ,$FX_DEFS.ToArray()
}
}
function Get-AmalgamatedScriptFunctionDefinitions {
param (
[parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[AllowEmptyString()]
[AllowNull()]
[System.String]
$Path
)
Process{
[System.String]$FX_DEFS = ""
Get-ScriptFunctionDefinitions -Path $Path |
ForEach-Object {
$FX_DEFS += "$_$([System.Environment]::NewLine)$([System.Environment]::NewLine)"
}
return $FX_DEFS
}
}
Write-Host
[System.String[]]$FX_NAMES = Get-ScriptFunctionNames -Path "$($PSCommandPath | Split-Path)/Functions.ps1"
[System.String[]]$FX_DEFS = Get-ScriptFunctionDefinitions -Path "$($PSCommandPath | Split-Path)/Functions.ps1"
[System.String] $FX_ALL_DEFS = Get-AmalgamatedScriptFunctionDefinitions -Path "$($PSCommandPath | Split-Path)/Functions.ps1"
. ([System.Management.Automation.ScriptBlock]::Create($FX_ALL_DEFS)) #The functions in Functions.ps1 are created in the current script.
Write-InfoBlue "Printed from imported function."
Check: Dot Sourcing operator.
Dot Source
ScriptBlock class
Console Output

Adding following to Main.ps1 we can test the 3 functions.
Write-Host "• TEST 1" -ForegroundColor Magenta
$FX_NAMES |
ForEach-Object {
Write-Host $_
}
Write-Host
Write-Host "• TEST 2" -ForegroundColor Magenta
foreach($value in $FX_DEFS)
{
Write-Host $value
Write-Host "███" -ForegroundColor DarkGray
}
Write-Host
Write-Host "• TEST 3" -ForegroundColor Magenta
Write-Host $FX_ALL_DEFS
Console Output

3. EXTRA SOLUTION - SPECIAL CASE
When obtaining the definitions of the functions it can be useful to use them to invoke commands on remote computers that do not contain the definition of the local functions, we simply obtain the definitions and pass them through parameters as follows.
If you need run powershell commands in remote computer, please install
Powershell Core on remote computer.
Local File
PrintColorFunctions.ps1
Same content as Solution 1's script.
Local file
Main.ps1
$FX_ALL_DEFS = Get-AmalgamatedScriptFunctionDefinitions -Path "$($PSCommandPath | Split-Path)/Functions.ps1"
$R_HOST = "192.168.211.1"
$R_USERNAME = "root"
$R_PORT = "2222"
$R_SESSION = New-PSSession -HostName $R_USERNAME@$($R_HOST):$R_PORT #//Connected by OpenSSL, private key added to OpenSSH Session Agent. If you need login by password, remove the private key from OpenSSH Session Agent and write as follows user:pass@host:port $($R_USERNAME):$R_PASS@$($R_HOST):$R_PORT
Invoke-Command -ArgumentList $FX_ALL_DEFS,"Joma" -Session $R_SESSION -ScriptBlock{ #// -ArgumentList function definitions and a name.
Param($fxs, $name) #// Param received by remote context.
. ([System.Management.Automation.ScriptBlock]::Create($fxs)) #//Creating function definitions in remote script context.
Clear-Host
Write-Host "Running commands in my remote Linux Server" -ForegroundColor Green #//Powershell Core cmdlet
#//We can use Write-InfoBlue on this script context.
Write-InfoBlue ($(Get-Content /etc/*-release | Select-String -Pattern "^PRETTY_NAME=.*" ).ToString().Split("=")[1]) #//Created function + cmdlets combo
Write-InfoBlue $(uname -a) #//Created function + Native remote command
Write-InfoBlue $(whoami) #//Cmdlet + Native remote command
printf "Hello! $name" #//Native remote command
Write-InfoBlue "Local function executed in remote context"
}
Remove-PSSession -Session $R_SESSION
Console Output

.ps1was a.psm1instead, it'd be a module and getting the list of functions would be as easy as(Import-Module C:\someScript.psm1 -Passthru).ExportedFunctions.Values. (Invoke with&$_.ScriptBlockas per Martin's answer.)