Ejecutar la función de PowerShell desde el script de Python

Tengo la necesidad de ejecutar una función de PowerShell desde un script de Python. Los archivos .ps1 y .py actualmente se encuentran en el mismo directorio. Las funciones que deseo llamar están en el script de PowerShell. La mayoría de las respuestas que he visto son para ejecutar scripts completos de PowerShell desde Python. En este caso, estoy intentando ejecutar una función individual dentro de un script de PowerShell desde un script de Python.

Aquí está el ejemplo de script de PowerShell:

# sample PowerShell
Function hello
{
    Write-Host "Hi from the hello function : )"
}

Function bye
{
    Write-Host "Goodbye"
}

Write-Host "PowerShell sample says hello."

y el script de Python:

import argparse
import subprocess as sp

parser = argparse.ArgumentParser(description='Sample call to PowerShell function from Python')
parser.add_argument('--functionToCall', metavar='-f', default='hello', help='Specify function to run')

args = parser.parse_args()

psResult = sp.Popen([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
'-ExecutionPolicy',
'Unrestricted',
'. ./samplePowerShell',
args.functionToCall],
stdout = sp.PIPE,
stderr = sp.PIPE)

output, error = psResult.communicate()
rc = psResult.returncode

print "Return code given to Python script is: " + str(rc)
print "\n\nstdout:\n\n" + str(output)
print "\n\nstderr: " + str(error)

Entonces, de alguna manera, quiero ejecutar la función 'hello ()' o la función 'bye ()' que está en la muestra de PowerShell. También sería bueno saber cómo pasar parámetros a la función. ¡Gracias!

Respuestas a la pregunta(1)

Su respuesta a la pregunta