Solved

Invoking powershell command

Posted on 2008-06-26
6
5,249 Views
Last Modified: 2010-04-21
HI Experts

Please see code snipped , I am trying to call a powershell command from C# and got the following error:


"Cannot invoke this function because the current host does not implement it."

I have followed http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=2365137&SiteID=17 , but still have the same error.

Thanks
// create Powershell runspace
            Runspace runspace = RunspaceFactory.CreateRunspace();
            // open it
            runspace.Open();         
            Command cmd = new Command("Get-Credential");
            cmd.Parameters.Add("Credential", "user");
            // create a pipeline and feed it the command
            Pipeline pipeline = runspace.CreatePipeline();
            pipeline.Commands.Add(cmd);
            // execute the commnand
            Collection<PSObject> results = pipeline.Invoke();
            // close the runspace
            runspace.Close();

Open in new window

0
Comment
Question by:elimesika
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 21878150
I am not sure what your going for, but Get-Credential is going to want to prompt you for a password and that cannot be passed via parameter.

Why do you want to use Get-Credential?
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 21878270
0
 
LVL 19

Author Comment

by:elimesika
ID: 21892436
HI

thanks for your respond.

I am trying to implement my own Login cndlet which has the following format

Login-Application [-User <user>] [-Password <password>] [-Domain <domain>]

If the user does not give any parameter and runs only

Login-Application

I want to prompt him to enter the user, password, domain manually
I thought that I can use Get-Credentials for that.

0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 18

Accepted Solution

by:
BSonPosh earned 500 total points
ID: 21892668
Naaa... You dont need to for this. You can do a prompt like you normally would do in C# and store the creds in a system.management.automation.pscredential.pscredential Object. Tring to use Get-Credentials for this would be overly complicated as you have to handle the prompts.
0
 
LVL 19

Author Closing Comment

by:elimesika
ID: 31470979
Thanks a lot for your time.
0
 
LVL 1

Expert Comment

by:JElster
ID: 33619911
How did you do this?  thanks
store the creds in a system.management.automation.pscredential.pscredential Object. Tring to use Get-Credentials for this would be overly complicated as you have to handle the prompts.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

740 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