ASP.NET and PowerShell filepath question

Posted on 2011-05-05
Last Modified: 2012-05-11
I have the following code that calls a cmdlet in Powershell via C#. It works with any cmdlets that doesn't require a file path. ie.
//doesn't work, I get the following error: The term 'dir c:\inetpub\wwwroot\pdf\*.pdf | foreach-object { Start-Process -FilePath $_.FullName -verb Print}' 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.

It works in Powershell window, but not in ASP.NET C#, I'm I missing something?
I don't get why it doesn't like the filepaths. It's not a permission issue.
Command mycommand = new Command(@"dir c:\inetpub\wwwroot\pdf\*.pdf | foreach-object { Start-Process -FilePath $_.FullName -verb Print}");
//Code below works, no errors and also other cmdlets.
//Command mycommand = new Command(@"get-psdrive");


Question by:7of9121098
    LVL 9

    Accepted Solution


    Author Comment


     I got this far, I know it's not  a permission issue, I run the following code:
     shell.Commands.AddScript(@"cd c:\users\pdf");
      shell.Commands.AddScript(@"dir r*.pdf");

     the object displays all of the pdfs in the current PDF directory. the issue I get is in the Foreach-object command it doesn't like it. I just need to know how to reference the foreach-object via
    foreach-object { Start-Process -FilePath $_.FullName -verb Print};


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    iTextSharp 3 33
    ASP.NET MVC Create/Edit ViewModel 7 51
    Gridview Edit Row 10 34
    Put text in a picture ASP.NET C# 2 26
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now