0

I am writing a plug-in for a software using C#. My plug-in generates a directory, containing a couple of text files, that I need to transfer to a computational cluster. At the moment I am transferring the files manually with the PowerShell (or the Ubuntu plug-in for Windows) using "scp -r -P location/on/windows location/on/cluster", but I would like to do this step automatically by including it in my plug-in.

I have looked around online for guidance and I have found some helpful documentation, but I am still quite lost.

So far I've managed to open the shell, but how to add a sequence of commands I still don't understand.

  if(x)
  }
      OpenPowerShell(@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe");
  }


  static void OpenPowerShell(string path)
  {
    Process.Start(path);
  }

Could someone please help me out with this or point to some helpful documentation?

Thanks, David

7
  • Ideally, you should use the PowerShell Class to execute PowerShell commands from C#. Commented Jan 14, 2020 at 16:04
  • @boxdog I am writing a plugin for Grasshopper using Visual Studio and when I try Powershell.Create(...); it is not recognized, what am I missing here? Commented Jan 14, 2020 at 16:08
  • Did you include System.Management.Automation.dll in your project? You can get a copy by running this in the PowerShell console: Copy ([PSObject].Assembly.Location) "$env:USERPROFILE\Desktop" Commented Jan 14, 2020 at 16:11
  • @boxdog that did the trick! Now I just need to figure out how to use this class;) Commented Jan 14, 2020 at 16:17
  • Have you thought of using c# version of the code instead of bringing powershell in the mix? like. Directory.Move(sourceDirName, destDirName);. If you have to call powershell, then look into using RunspaceFactory and Pipeline Commented Jan 14, 2020 at 16:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.