Remote_Function_Template.ps1

fucntion Function-Name {
    param (
        [string]$Machine
    )
    try {
    # Code to execute
        # $Credential is stored as a global variable and uses the Get-Credential command.
    $Session = New-PSSession -ComputerName $Machine -Credential $Credential
    $ScriptBlock = (Read-Host -p "Enter name of function to run remotely")
    Invoke-Command -Session $Session -ScriptBlock $ScriptBlock
    Remove-PSSession -Session $Session
    } catch {
        Write-Host "An error occurred: $($_.Exception.Message)"
        return $null
    }
}