none
Calling a PowerShell script which contains functions from C# RRS feed

  • Question

  • Hi,

    From a C# application I am calling a Powershell script. This worked as expected until a function was defined and added in the script. No change was made to the C# code. From then on, there is an error:

    The term 'functionName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    The C# application uses the PowerShell Class and the invoke method.

    I wonder if functions are can be used within this context.

    Regards,

    Philippe

    Thursday, October 19, 2017 1:28 PM

All replies

  • Where is that error message? Is it from PowerShell code or C# code? What line is the error from? How do you get the error; what are you doing when it happens? Is "functionName" a PowerShell or C# function?


    Sam Hobbs
    SimpleSamples.Info

    Thursday, October 19, 2017 6:06 PM
  • Hi Sam,

    The error message is coming from the PowerShell script. It occurs when one of the functions in the script are executed. "functionName" is just a substitute for the real function in the script being called.

    One of the functions in the script is:

    ## Function remove Exchange remoting session
                Function Remove-ExSession
                {
                    $Session = Get-PSSession | ?{$_.ConfigurationName -eq "Microsoft.Exchange"}
                    Remove-PSSession $Session
                }

    As already said, everything worked fine until a function was added in the script.

    Regards

    Philippe

    Thursday, October 19, 2017 7:01 PM
  • So this seems to be a PowerShell question. It would be best in a PowerShell forum but I don't know what that is.


    Sam Hobbs
    SimpleSamples.Info

    Thursday, October 19, 2017 7:45 PM