Advertisement

06.26.2008 at 07:19AM PDT, ID: 23518230
[x]
Attachment Details

Invoking powershell command

Asked by elimesika in MSH/Monad PowerShell, C# Programming Language, Scripting Languages

Tags: , ,

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.

ThanksStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
// 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();
[+][-]06.26.2008 at 12:26PM PDT, ID: 21878150

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 12:40PM PDT, ID: 21878270

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 04:59PM PDT, ID: 21892436

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.28.2008 at 06:50PM PDT, ID: 21892668

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MSH/Monad PowerShell, C# Programming Language, Scripting Languages
Tags: powershell, c#, script
Sign Up Now!
Solution Provided By: BSonPosh
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906