API To Powershell Script

Micah Holmes 126 Reputation points
2021-03-26T18:32:27.413+00:00

I'm trying to setup an API call that will trigger it to run a PowerShell script. I found this tut https://www.youtube.com/watch?v=cIrCce5l7NU on how to call it from a desktop app. But when I try to set it up I get errors and its not letting me setup "RuneSpace"

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GSU_API  
{  
    public class FIM_Functions  
    {  
        public string Run_FIM_Script_AD()  
        {  
            RunSpace runspace = RunSpaceFactory.CreateRuneSpace();  
  
        }  
    }  
}  

I have the requested package I think:
81956-image.png

Not sure why this is giving error

Windows for business | Windows Server | User experience | PowerShell
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 91,511 Reputation points
    2021-03-26T18:54:43.213+00:00

    It is CreateRunspace, not CreateRuneSpace...

    (and you don't need to add the package, you can add directly the Reference to System.Management.Automation

    (on my OS, I have it at :"C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll")

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.