[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


ASP.NET and PowerShell filepath question

Posted on 2011-05-05
Medium Priority
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

Accepted Solution

radcaesar earned 500 total points
ID: 35700472

Author Comment

ID: 35707761

 I got this far, I know it's not  a permission issue, I run the following asp.net 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 asp.net.
foreach-object { Start-Process -FilePath $_.FullName -verb Print};


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 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