• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

ASP.NET and PowerShell filepath question

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");

Thanks.

0
7of9121098
Asked:
7of9121098
1 Solution
 
radcaesarCommented:
0
 
7of9121098Author Commented:

 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};

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now