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#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,521 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 Answers by the question author, which helps users to know the answer solved the author's problem.