API To Powershell Script

Micah Holmes 121 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

C#
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.
10,223 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,636 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