question

MicahHolmes-1650 avatar image
0 Votes"
MicahHolmes-1650 asked Castorix31 answered

API To Powershell Script

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

dotnet-csharpwindows-server-powershell
image.png (1.3 MiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
1 Vote"
Castorix31 answered

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")



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.