Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3324114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:22:58+00:00 2026-05-17T23:22:58+00:00

I’ve been working on this issue for a couple days and have read several

  • 0

I’ve been working on this issue for a couple days and have read several posts here, but I can’t get my implementation to work. I am calling the powershell script during the Commit custom action. When I get to the pipeline.Invoke() method, I get an exception that says the entire script “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.”

Here is my script:

Param(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [string]$installPath
    );

schtasks /create /TN MyTask /RU domain\account /RP password /xml $installPath\MyTaskSchedule.xml;

I’ve tried it with and without the trailing semi-colons, with and without a wrapping function. I’ve verified that the C# code is passing the correct install path and that the xml file exists in the directory before this step is hit. I can run this from PowerShell itself and it works just fine.

Here is my code:

public override void Commit( System.Collections.IDictionary savedState )
{
    base.Commit( savedState );

    String targetDirectory = this.Context.Parameters["TDir"].ToString();
    String script = System.IO.File.ReadAllText( targetDirectory + "TaskScheduler.ps1" );

    RunspaceConfiguration c = RunspaceConfiguration.Create();

    using ( Runspace runspace = RunspaceFactory.CreateRunspace() )
    {
        runspace.Open();
        using ( Pipeline pipeline = runspace.CreatePipeline() )
        {
            Command myCommand = new Command( script );
            CommandParameter param = new CommandParameter( "installPath", targetDirectory.Replace("\\\\", "\\") );

            myCommand.Parameters.Add( param );
            pipeline.Commands.Add( myCommand );

            try
            {
                 pipeline.Invoke();
            }
            catch ( Exception e )
            {
                 MessageBox.Show( e.Message );
            }
        }
    }
}

When the exception is caught at pipeline.Invoke, the entire script is displayed (with the $installPath instead of the actual path) as a string before the error message detailed above. I’ve tried several checks within the script itself, but I get the same results no matter what, which tells me that the runspace just doesn’t like the script itself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:22:58+00:00Added an answer on May 17, 2026 at 11:22 pm

    You should pass true as the second parameter in the constructor: new Command(script, true). It tells that the command is a script code, not a command name.

    Here is a working PowerShell analogue of your code:

    # This script calls the external command (cmd) with passed in parameter
    $script = @'
    param
    (
        [parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [string]$installPath
    )
    
    cmd /c echo $installPath
    '@
    
    # Note: the second parameter $true tells that the command is a script code, not just a command name
    $command = New-Object Management.Automation.Runspaces.Command $script, $true
    $param = New-Object Management.Automation.Runspaces.CommandParameter "installPath", "C:\UTIL\INSTALL"
    $command.Parameters.Add($param)
    
    $rs = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
    $rs.Open()
    $pipeline = $rs.CreatePipeline()
    $pipeline.Commands.Add($command)
    $pipeline.Invoke()
    

    It prints (in the console host):

    C:\UTIL\INSTALL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.